Help me with CJuiDatePicker

Hi everybody,

I have a problem with CJuiDatePicker.

I create class TimChuyenxeForm in \protected\models

<?php




class TimChuyenxeForm extends CFormModel

{

  public $diemxp;  

  public $diemden;

  public $ngaykhoihanh;  


  public function rules() {

    return array(array('diemxp,diemden,ngaykhoihanh', 'required'));

  }

  public function safeAttributes() {

    return array('diemxp,diemden',);

  }


}

Then I create a component TimChuyenxe


?php


class TimChuyenxe extends CPortlet {


  public $title='Tìm Chuyến';


  public function renderContent() {

    $form = new TimChuyenxeForm();

    $this->render('timChuyenxe', array('form'=>$form));

  }


}

Form timChuyenxe.php follows


<?php $url = $this->getController()->createUrl('chuyenxe/getChuyenxe'); ?>

<?php echo CHtml::beginForm($url); ?>

<div class="row">

<?php echo CHtml::activeTextField($form,'diemxp') ?>

<?php echo CHtml::error($form,'diemxp'); ?>

<?php echo CHtml::activeTextField($form,'diemden') ?>

<?php echo CHtml::error($form,'diemden'); ?>

<?php 

<?php $form->ngaykhoihanh=$this->widget('zii.widgets.jui.CJuiDatePicker',

	    array(

	      'name'=>Chtml::activeName($form,'ngaykhoihanh'),    

	      'value' => $form->attributes['ngaykhoihanh'],

             'themeUrl' => Yii::app()->baseUrl.'/css/jui' ,

				'theme'=>'base', 

				'cssFile'=>array('jquery-ui.css'),

				'options' => array(

						'dateFormat'=>'dd/mm/yy',

						'changeMonth' => 'true',

						'changeYear' => 'true',

						'duration'=>'fast',

						'showAnim' =>'slide',

						 ),

 	    )

	);

?>

<?php echo CHtml::SubmitButton('Tìm'); ?>

</div>

<?php echo CHtml::endForm(); ?>

I want to get value of dienxp,diemden and ngaykhoihanh, but I can’t.

$form->ngaykhoihanh is empty.

Could you please help me?

Thanks.

Hi everybody,

I have get the value $form->ngaykhoihanh with format dd/mm/yy such as 20/05/2011.

But I don’t know to get the value of the day from it. Because maybe it seem a string.

Have we got any function to get the day, the month, the year from it?

Help me please!

Regard.

As far as I can see, the problem is with how you declare your DatePicker widget - you shouldn’t set your attribute equal to it, but simply initialise the widget, and give it your model and attribute as parameters:


<?php echo CHtml::error($form,'diemden'); ?>

<?php 

<?php $this->widget('zii.widgets.jui.CJuiDatePicker',

            array(

              'name'=>CHtml::activeName($form,'ngaykhoihanh'),    

              'model' => $form,

              'attribute' => 'ngaykhoihanh',

              'themeUrl' => Yii::app()->baseUrl.'/css/jui' ,

              'theme'=>'base', 

              'cssFile'=>array('jquery-ui.css'),

              'options' => array(

                 'dateFormat'=>'dd/mm/yy',

                 'changeMonth' => 'true',

                 'changeYear' => 'true',

                 'duration'=>'fast',

                 'showAnim' =>'slide',

              ),

            )

        );

?>

Give it a try like that (note that I changed Chtml to CHtml for the activeName attribute too - I presume that was just a typo).

Gracias por el aporte. Es muy bueno.

Thanks for the post. Is very good.