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';
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.
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
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…