I have got a table relation of HAS_MANY like this
public function relations() {
// NOTE: you may need to adjust the relation name and the related
// class name for the relations automatically generated below.
return array(
'sinaisvitais' => array(self::HAS_MANY, 'Sinaisvitais', 'idUtente'),
'idEnf0' => array(self::BELONGS_TO, 'Enfermeiro', 'idEnf'),
'idServico0' => array(self::BELONGS_TO, 'Servico', 'idServico'),
'idDieta0' => array(self::BELONGS_TO, 'Dieta', 'idDieta'),
);
}
And my Search function is declared like this
public function search() {
// @todo Please modify the following code to remove attributes that should not be searched.
$criteria = new CDbCriteria;
$criteria->compare('idUtente', $this->idUtente);
$criteria->compare('idEnf', $this->idEnf);
$criteria->compare('idServico', $this->idServico);
$criteria->compare('nome', $this->nome, true);
$criteria->compare('idade', $this->idade);
$criteria->compare('dataNasc', $this->dataNasc, true);
$criteria->compare('dataInternamento', $this->dataInternamento, true);
$criteria->compare('morada', $this->morada, true);
$criteria->compare('idDieta', $this->idDieta);
$criteria->compare('dataIntervencao', $this->dataIntervencao, true);
$criteria->compare('sondaVesical', $this->sondaVesical);
$criteria->compare('ecd', $this->ecd);
$criteria->compare('idSinaisVitais', $this->idSinaisVitais);
$criteria->compare('riscoQueda', $this->riscoQueda);
$criteria->compare('riscoAlergia', $this->riscoAlergia);
$criteria->compare('riscoTransfusao', $this->riscoTransfusao);
$criteria->compare('riscoMultiRisco', $this->riscoMultiRisco);
$criteria->compare('obsQuadro', $this->obsQuadro, true);
$criteria->compare('obs', $this->obs, true);
return new CActiveDataProvider($this, array(
'criteria' => $criteria,
));
}
My controller is declared like this
public function actionAdmin() {
$model = new Utente('search');
$model->unsetAttributes(); // clear any default values
if (isset($_GET['Utente']))
$model->attributes = $_GET['Utente'];
$this->render('admin', array(
'model' => $model,
));
}
And my Gridview is declared like this
$this->widget(‘zii.widgets.grid.CGridView’, array(
'id' => 'utente-grid',
'dataProvider' => $model->search(),
'filter' => $model,
'columns' => array(
//'idUtente',
array('name' => 'idEnf0', 'header' => 'Enfermeiro', 'value' => '$data->idEnf0->nome'),
array('name' => 'idServico0', 'header' => 'Servico', 'value' => '$data->idServico0->nome', 'filter' => CHtml::activeTextField($model, 'idServico')),
array('name' => 'nome', 'header' => 'Nome', 'value' => '$data->nome'),
array('name' => 'idade', 'header' => 'Idade', 'value' => '$data->idade'),
array('name' => 'dataNasc', 'header' => 'Data Nascimento', 'value' => '$data->dataNasc'),
array('name' => 'idDieta0', 'header' => 'Dieta', 'value' => '$data->idDieta0->nome'),
array('name' => 'dataInternamento', 'header' => 'Data Internamento', 'value' => '$data->dataInternamento'),
array('name' => 'obsQuadro', 'header' => 'Quadro', 'value' => '$data->obsQuadro'),
array('name' => 'obs', 'header' => 'Observações', 'value' => '$data->obs'),
array('name' => 'sinaisvitais', 'header' => 'Sinais Vitais', 'value' => '$data->sinaisvitais->tas'),
When I try to access sinaisvitais->tas i get the following error
htmlspecialchars() expects parameter 1 to be string, array given
C:\xampp\htdocs\yii\framework\web\helpers\CHtml.php(158): CHtml::renderAttributes(array("name" => "Utente[sinaisvitais]", "type" => "text", "value" => array()))
All the other relations of 1:N work just fine… Can anyone help please… Many thanks.