jonny
(Jonny)
December 30, 2011, 7:30pm
1
Hello,
I’ve adjusted my SiteController.php to show
// limits query for index page results to 10
$Criteria = new CDbCriteria();
$Criteria->limit = 10;
// renders the view file 'protected/views/site/index.php'
// using the default layout 'protected/views/layouts/main.php'
$this->render('index', array(
'ItemDetails' => ItemDetail::model()->findAll($Criteria),
));
It just gets the last 10 records from my DB and I want to display these on my index.php page, if i use the following code in index.php view I can return my results, which is great.
<?php foreach($ItemDetails as $ItemDetail):?>
<tr>
<td><?php echo $ItemDetail->title;?></td>
<td><?php echo $ItemDetail->des;?></td>
</tr>
<?php endforeach;?>
My layout for my actual home page uses the index.php and column1.php view, what I’d like to do is be able to show the $itemDetails->title inside the column1.php view.
How do I go about doing this?
(I know this is a dumb question )
tri
(tri - Tommy Riboe)
December 30, 2011, 11:30pm
2
A) Declare $this->itemDetail in base controller. Assign to it in controller action. Check for value and display in column1.php.
or
B ) Declare $this->itemDetail in current controller. Assign to it in controller action. Check for existence and display in column1.php.
or
C) Use a clip.
/Tommy
jonny
(Jonny)
December 30, 2011, 11:50pm
3
Hello Tri,
Thanks for getting back to me, when you say
Where do you actually mean, I think i’m going to use the SiteController.php (actionIndex()) as that’s where I’m currently working.
Am I in the wrong place.
jacmoe
(Jacob Moena)
December 30, 2011, 11:53pm
4
Clips are great.
I have this code in my Controller::beforeAction:
$this->beginWidget('system.web.widgets.CClipWidget', array('id' => 'users_online'));
if (isset($this->users_online)) {
foreach ($this->users_online as $user)
if (isset($user)) {
echo '<b>' . ucfirst($user['username']) . '</b> <small>(';
echo 'Idle for ' . $user['TIMESTAMPDIFF(MINUTE, last_activity, UTC_TIMESTAMP())'] . ' minutes)</small><br/>';
}
} else {
echo 'none';
}
$this->endWidget();
Yes, in the controller.
Then I just do this in the views, like in column2.php:
<h2>Users Online</h2>
<?php echo $this->clips['users_online']; ?>
jonny
(Jonny)
December 30, 2011, 11:55pm
5
I don’t know what a clip is so I shall read up on it. So many cool things to learn!
jacmoe
(Jacob Moena)
December 30, 2011, 11:58pm
6
It’s Yii - get used to it!
I put the code in the Controller class - which means that every controller in my app has access to that clip.
jonny
(Jonny)
December 31, 2011, 12:01am
7
Thanks, i’ll no doubt be back with other questions as I go along