I have following method:
public function actionIndex() {
$companyModel = Company::model()->findAll();
$supplierProductModel = SupplierProduct::model()->findAll();
$this->render('index', array(
'companyData' => $companyModel,
'supplierProductData' => $supplierProductModel,
));
}
Here I have passed model objects to render function and want to access these objects in view (Active Relational Type) but when I am accessing its in view its showing error:
Trying to get property of non-object
view file (index.php)
echo $companyData->name . "\n";
echo $this->companyModel->phone . "\n";
echo $this->companyModel->fax . "\n";
echo $this->companyModel->cell . "\n";
Any help would be appreciated.
You are trying to get all the entries from the database as findAll() returns all data in multidimensional array of objects.If you need all the entries you could iterate over it in the view file and get the results as shown
In the View File do as shown
With this you get all the entries from the table
If you want to get a particular record use condition using Cdbcriteria and pass the object and get the single result
you need to declare $this->companyModel in your controller/action
with Company::model()->findAll() you get an array of Company-Models you can iterate over in your view-file.
It is happening becoz of findAll()
findAll() reruns all rows of company table in multidimensional array, so here $companyData is multidimensional Array, now change your code in index like bellow,
If you want a company data(single row), change your query like this
Send this to view
Now you can show the data using bellow code