how to use model inside column1.php instead of index.php view

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 :mellow: )

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

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.

:)

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']; ?>



I don’t know what a clip is so I shall read up on it. So many cool things to learn! :)

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.

Thanks, i’ll no doubt be back with other questions as I go along :D