[b]So I make one nice registration form using the MVC philosophy. My model extends AR from users. My View contains the fields and my Controller contains the actions.
So i put 3 drop downs to get birthday of users. I set birthday required on my model. But after validation errors the dropdowns don’t back on old position and it should. After validation success i used beforeSave() to create a date from dropDown values but i can’t access them.
Why???
What is the better way to do this? [/b]
public function getDays()
{
for ($i=1;$i<=31;$i++)
{
$days["{$i}"]="{$i}";
}
return $days;
}
public function getMonths()
{
$monthNames = array('','January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December');
for ($i=1;$i<=12;$i++)
{
$months["{$i}"]=Yii::t('default',$monthNames[$i]);
}
return $months;
}
public function getYears()
{
for ($i=date('Y');$i>=1900;$i--)
{
$years["{$i}"]="{$i}";
}
return $yers;
}
and on my view i put this
...
<div class="row">
<?php echo $form->labelEx($model,'birthday'); ?>
<?php echo CHtml::activeDropDownList($model,'day', $this->getDays()); ?>
<?php echo CHtml::activedropDownList($model,'month', $this->getMonths()); ?>
<?php echo CHtml::activedropDownList($model,'year', $this->getYears()); ?>
</div>
...
on my model i put this
public function beforeSave()
{
...
$this->birthday=date('Y-m-d', strtotime($this->year . '-' . $this->month . '-' . $this->day));
...
return true;
}