show date from datepicker

hello,

pleasei have my datepicker and iwant to show the value selected how can i do it!!





<?php 


$this->widget('zii.widgets.jui.CJuiDatePicker', array(

    'name'=>'Utilisateur[firstDate]',

	'model'=>$model,

	'attribute'=>'firstDate',

	'value'=>$model->firstDate,

	

    'options'=>array('showAnim'=>'fold',

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

    ),

    'htmlOptions'=>array(

        'style'=>'height:20px;',

    ),

)); 


?>



any help please, thank you

It should be done automatically. Did you try to remove ‘value’ and ‘name’ options?

yes i’ve tried it, i want to show it with an echo like




echo $model->firstDate;



Do you have a ‘safe’ rule for your model attribute?

check your database to make sure your data is saved first. Your code should output the date without further work.

thank you all for your replay,

i will explain you my problem, i have to execute this query and put the result in a CGridview

this is the query in my model :




 $criteria->select='t.loginu , sum(envoiglobal.nbree) as nbr, sum(envoiglobal.nbredeferred) as nbrdef, sum(envoiglobal.clicks) as clicks, ROUND((sum(envoiglobal.clicks)/sum(envoiglobal.nbree))*100,2) as pr';

		

		$criteria->join= 'JOIN envoiglobal ON t.idutilisateur= envoiglobal.idutilisateur';

		$criteria->condition="t.idutilisateur = envoiglobal.idutilisateur and dateenvoi= '$firstDate' ";

		$criteria->group='loginu';



firstDate should be selected by datepicker





<?php 


echo $model->firstDate;

$this->widget('zii.widgets.jui.CJuiDatePicker', array(

    'name'=>'Utilisateur[firstDate]',

	'model'=>$model,

	'attribute'=>'firstDate',

	'value'=>$model->firstDate,

	

    'options'=>array('showAnim'=>'fold',

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

    ),

    'htmlOptions'=>array(

        'style'=>'height:20px;',

    ),

)); 


?>



while executing, it doesn’t know the variable firstDate

any help please!!!!




$firstDate = Utilisateur[firstDate];


$criteria->select='t.loginu , sum(envoiglobal.nbree) as nbr, sum(envoiglobal.nbredeferred) as nbrdef, sum(envoiglobal.clicks) as clicks, ROUND((sum(envoiglobal.clicks)/sum(envoiglobal.nbree))*100,2) as pr';

                

$criteria->join= 'JOIN envoiglobal ON t.idutilisateur= envoiglobal.idutilisateur';

$criteria->condition="t.idutilisateur = envoiglobal.idutilisateur and dateenvoi= '$firstDate' ";

$criteria->group='loginu';

$criteria->params=array(':firstDate' => $firstDate);



Nothing works out of the box. You need to tell Criteria what is $firstDate by binding the params as showed above.

how can i bind the params ?? can you please explain me




$firstDate = Utilisateur['firstDate'];

$criteria->params=array(':firstDate' => $firstDate);



thanks,

but it doesn’t work, it doesn’t know the variable firstDate, i get this error "Parse error: parse error in …’ on this line

Everything selected in that query has no attribute nor field specified as firstDate. Query returned should fill the attributes automatically if those attributes are public or come from table schema in the model.




// this selection

t.loginu , sum(envoiglobal.nbree) as nbr, sum(envoiglobal.nbredeferred) as nbrdef, sum(envoiglobal.clicks) as clicks, ROUND((sum(envoiglobal.clicks)/sum(envoiglobal.nbree))*100,2) as pr'

// returns loginu, nbr, nbrdef, clicks and pr as attributes... 



If the query above doesn’t specify firstDate, how do you want it to be set on the Model? Moreover, my guess is that only lognu is set if you didn’t include public properties to the model nbr, nbrdef, clicks and pr. Include t.firstDate to the query and you will see it in your model.

thank you for your reply,

but it isn’t the problem, firstDate is not a table field, it’s only a variable public where the date selected by datepicker will be saved, then i will execute my query by testing on dateenvoi which is a field in table utilisateur




$criteria->condition="dateenvoi='$firstDate'";



Is that value submitted? If that is so, then you get it as




// depending if you form's method is post or get

$firstDate = $_POST['Utilisateur']['firstDate'];

//or

$firstDate = $_GET['Utilisateur']['firstDate'];


// or 


$model = new Utilisateur();

$model->attributes = $_POST['Utilisateur']; // or $_GET I do not know how you post your form

echo $model->firstDate; //<--- holds the value firstDate



Make sure you check that value when posted (if isset($_POST[‘Utilisateur’]). If you datePicker its name is ‘name’=>‘Utilisateur[“firstDate”]’ you don’t need ‘model’ nor ‘attribute’ to be set, and viceversa…

Cheers