Jump to content
Larry Ullman's Book Forums

Accessing A Controller Variable Via Cdetailview Widget

Recommended Posts

Hi, I'm using Yii version 1.1.13. I've generated a variable in a controller, that I need to display in the view file "_view.php". I pass the variable to "view.php" with render, and I can access it there. But I can't figure out how to access the variable from "_view.php", which uses the CDetailView widget. How is this done? Am I missing something? You would think this would be very easy, since it is such a common task.


Thanks for any tips,

Larry Z.


Link to post
Share on other sites

For Pete's sake, I just figured it out, thanks to this post:




and then this made more sense:




At least this is one way to do it I suppose. You can access data in the database directly using a relation defined in your model.


In my Course model I have this relation:


'department' => array(self::BELONGS_TO, 'Department', 'department_id'),


In the view.php file I add an attribute to the CDetailView widget that accesses the data:


<?php $this->widget('zii.widgets.CDetailView', array(
                array('label'=>'Department', 'name'=>'department_name', 'value'=>$model->department->department_name),
)); ?>


And in the _view.php file:
<b><?php echo CHtml::encode($data->getAttributeLabel('department_id')); ?>:</b>
<?php echo CHtml::encode(department_name); ?>
<br />


But what if you make a calculation in a controller, which is not stored in the database, and want to display it in the _view.php file? Would it be available in $this->some_variable? OK I'll test...
Larry Z.
Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...