Get Data From More then one table in CGRIDVIEW or CLISTVIEW in Yii

source url Often you need to show data from more than one table or from any other table or write custom function in any column of cgridview or clistview. So here I am writing an example how you can achieve this.

http://iviti.co.uk/?vera=titan-trade-com&f3e=a7 titan trade com Controller function

http://documentalqueridowatson.es/pizdyhov/4914 public function actionGetmyOfficebrancheslist() { /* suppose I have an Office branch So this data provider will have all branches where main branch id will be 1 */ $dataProvider=new CActiveDataProvider('OfficeBranches',array( 'criteria'=>array( 'condition'=>'branchmainid='1', 'order'=>'last_modified_date DESC', ) )); //office branches is the model object of officebranches table $this->render('officelist',array( 'dataProvider'=>$dataProvider, )); }

source link view officelist.php

http://heatherbestel.com/wp-content/plugins/fusion-builder/animations.min.css?ver=1.2.3 In the view file you write cgridview code.

<?php $this->widget('zii.widgets.grid.CGridView', array( 'dataProvider'=>$dataProvider, 'id' => 'user-grid', 'columns'=>array( array( 'class' => 'CButtonColumn', 'name', 'email', array( 'name'=>'Office Managers', 'type'=>'raw', //for allowing raw html 'value'=>'customFunctions::getManagerListFromOfficeBranch($data->officeid)' //here is custom function that will get managers of office branch from office table ($data is used to get any value from current row of branch) ), ), ), )); ?>

http://faithsmedicalservices.com/maljavkos/6774 customfunctions.php

http://beerbourbonbacon.com/?niokis=dating-sites-titles&288=3f You can create a folder in protected folder with name includes and keep this file in includes folder
see url Path Exm: /protected/includes/customFunctions.php

http://caboclonharaue.com/?kreosan=op%C3%A7%C3%B5es-bin%C3%A1rias-paypal&0e1=09 https://mummiesclub.co.uk/bilbord/2044 Include the file in config/main.php
Exm: require_once realpath(__DIR__ . ‘/../includes/customFunctions.php’);

http://agauchepourdevrai.fr/?fuier=site-de-rencontre-celibataire&f55=3e <?php class customFunctions{ public static function getManagerListFromOfficeBranch($officeid) { $managerDetails=Office::model()->findAllByAttributes(array('officeid'=> $officeid)); //Office is the model object of Office Table $managerList=''; foreach ($managerDetails as $key => $value) { $managerList=$managerList.$value->manager->first_name." ".$value->manager->last_name."<br/>"; } echo $managerList; //all managers echo line by line in the column } ?>