hi
i use this code
$data = $model->search()->getData();
the problem is that i cant $data->attribute or $data->relation->attribute
Can you show me whats wrong
hi
i use this code
$data = $model->search()->getData();
the problem is that i cant $data->attribute or $data->relation->attribute
Can you show me whats wrong
CActiveDataProvider::getData() returns an array of AR objects.
$dataArray = $model->search()->getData();
foreach($dataArray as $data)
echo $data->xxx;
thanks but can’t acess related model
and is there.
using $criteria->with = array(‘casas’, ‘precos’);
and data is returned correctly.
Dont understand
Sorry, I don’t understand your problem.
Could you post your code that is related to the problem?
model search
$criteria->compare('valorcaucao', $this->valorcaucao, true);
$criteria->compare('deficientes', $this->deficientes);
$criteria->compare('casas.propid', $uid);
$criteria->with = array('casas', 'precos');
$uid = Yii::app()->user->name == ("admin") ? "" : Yii::app()->user->id;
$test = new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
return $test;
}
controller
public function actionSearch() {
$model = new Casa('search');
$model->unsetAttributes(); // clear any default values
if (isset($_POST['Casa']))
$model->attributes = $_POST['Casa'];
// $data = $model->with('precos')->search()->getData();
$data = $model->search()->getData();
$this->render('quickSearch', array(
'model' => $model,
'data' => $data,
));
}
view
<?php
CVarDumper::dump($data->precos);
$this->widget('zii.widgets.CListView', array(
'dataProvider'=>$model->search(),
'itemView'=>'_view',
));
So, I said that CActiveDataProvider::getData() returns an array of AR objects.
$data in the above is not an object, but an array of objects.
And you don’t have to retrieve the data using CActiveDataProvider::getData() by yourself.
CListView (or CGridView) will do it for you.
Would you please read this wiki article (I said it to you once before, and say it again).
http://www.yiiframework.com/wiki/381/cgridview-clistview-and-cactivedataprovider/
Interesting.
But my friend , i would like to filter also by result of function.
imagine :
$reserva= new Reserva();
$criteria->compare(‘cod_casa’, $reserva->checkDays($this,1));
the problem is that i have a search form with 2 date parameters that dont exist in the model. i want to return only the $model->search() items that pass in checkdays().
following oop aproach
Oh, dear Led, I’m sorry I don’t understand what you mean, again.
You have to elaborate it a bit more in details. I can’t imagine what you are trying to do at all.
[/code]
[quote="softark, post:9, topic:54359"]
Oh, dear Led, I'm sorry I don't understand what you mean, again. <img src='http://www.yiiframework.com/forum/public/style_emoticons/default/biggrin.gif' class='bbc_emoticon' alt=':D' />
You have to elaborate it a bit more in details. I can't imagine what you are trying to do at all.
[/quote]
[code]public function checkDays($model, $state) {
$myproc2 = "Select preco.id,inicio,fim,cod_casa,reserva.id from preco left join reserva on preco.id=reserva.idpreco where cod_casa = " . $model->precos->cod_casa . " AND livre = 0 and fim > " . date('Y/m/j') . " and (reserva_state = " . Reserva::RESERVA . " OR reserva_state = " . Reserva::SINAL . ") order by idpreco desc";
$ocupas = Yii::app()->db->createCommand($myproc2)->query()->readAll();
foreach ($ocupas as $ocupa) {
$starte = $ocupa['inicio'];
$dtEnde = $ocupa['fim'];
$dtLoop = date('Y/m/j', strtotime("+1 day", strtotime($starte)));
$dtEnd = date('Y/m/j', strtotime("-1 day", strtotime($dtEnde)));
While (strtotime($dtLoop) <= strtotime($dtEnd)) {
$inic = date('Y/m/j', strtotime($model->precos->inicio));
$fim = date('Y/m/j', strtotime($model->precos->fim));
While (strtotime($inic) <= strtotime($fim)) {
if ($inic == $dtLoop && ($state == self::SINAL || $state == self::RESERVA)) {
Yii::app()->user->setFlash('error', $inic . ' Este dia ja esta reservado ! Reserva ' . $ocupa['id'], true);
return TRUE;
}
$inic = date('Y/m/j', strtotime("+1 day", strtotime($inic)));
}
$dtLoop = date('Y/m/j', strtotime("+1 day", strtotime($dtLoop)));
}
}
return FALSE;
}
let’s say remove from $model->search() if checDays() return true
also a problem because pagination of $data = $model->searchAll()->getData();
maybe little tired , and when you don’t know the framework is as if you were blind.
thanks for your patiente , i’ll stick with sql
Led,
I’m sorry but I’m not familiar with your native language, so I can’t imagine what you are doing in your code. “preco”, “casa”, “reserva”, “inicio”, “fim” … I don’t know what they mean.
Could you explain what you want to do in English, not in PHP code?
You have to note that nobody knows what your data models (i.e. Preco and Reserva) are like except you. You haven’t provided us yet with a very basic information about the data models in question.
I’ve follow another approach. thanks very much
Ah, that’s fine. No problem.