how to get name based on id from DB table in yii framework -
i developing web application using yii framework, have 1 table called "userprofile" in database. have tried export userprofile data excel file, working fine userprofile table fields user profile table
id username password studentname classid parentname email 1. xxxxx asdf yyyyy 2 pqrs xy@gmail.com
classname table
classid classname 1. xxxxx 2. yyyyy 3. zzzzz
in controller have 1 function called actionexcelexport() , has
$content = $this->renderpartial("excel",array("model"=>puserprofile::model()->findall()),true);
in above line calling 1 excel file called excel , excel.php
<table> <tr> <td style="background-color: #555;color:#fff">user name</td> <td style="background-color: #555;color:#fff">student name</td> <td style="background-color: #555;color:#fff">classid</td> <td style="background-color: #555;color:#fff">parent name</td> <td style="background-color: #555;color:#fff">email</td> </tr> <?php foreach($model $data):?> <tr> <td> <?php echo $data->username ?> </td> <td> <?php echo $data->studentname ?> </td> <td> <?php echo $data->classid ?> </td> <td> <?php echo $data->parentname ?> </td> <td> <?php echo $data->email ?> </td> </tr> <?php endforeach; ?> </table>
my reqirement:- in excel file want classname instead of classid example if classs id '2', classname 'yyyy' should in excel file how retrive classname based on classid please me
i got solution problem in excel.php, instead of line
classid ?>
i changed class->classname?>
class->classname = userprofile model has relation function , has relation because using foreign key table taking 'class' model , ('classname') database field name
Comments
Post a Comment