chanhle
chanhle

Reputation: 168

What is $data in _view.php of blog (demos folder) of yii framework is?

I confuse about $data in blog/views/post/_view.php of blog demo of yii framework How I get this attribute of $data? Where I can find the define of $data? I find in source but doesn't see any line about author->username ,url commentCount?

<div class="post">
    <div class="title">
        <?php echo CHtml::link(CHtml::encode($data->title), $data->url); ?>
    </div>
    <div class="author">
        posted by <?php echo $data->author->username . ' on ' . date('F j, Y',$data->create_time); ?>
    </div>
    <div class="content">
        <?php
            $this->beginWidget('CMarkdown', array('purifyOutput'=>true));
            echo $data->content;
            $this->endWidget();
        ?>
    </div>
    <div class="nav">
        <b>Tags:</b>
        <?php echo implode(', ', $data->tagLinks); ?>
        <br/>
        <?php echo CHtml::link('Permalink', $data->url); ?> |
        <?php echo CHtml::link("Comments ({$data->commentCount})",$data->url.'#comments'); ?> |
        Last updated on <?php echo date('F j, Y',$data->update_time); ?>
    </div>
</div>

Can you help me to explain or give me some link or some keywork. Thank for everything!

Upvotes: 1

Views: 2630

Answers (2)

Onkar Janwa
Onkar Janwa

Reputation: 3950

$data is an object of model class having single row of data. author is a relation to another model of the model whose instance is $data. $data->author->username Here username is a variable of the model whom author points. $data->author also treated as an object. It will just execute a relational query to the model whom author points.

You can see the relations of the model in relations() function of the model. Try out guide of yii you will find your answer.

Upvotes: 2

user1233508
user1233508

Reputation:

See documentation for CListView:

The above code first creates a data provider for the Post ActiveRecord class. It then uses CListView to display every data item as returned by the data provider. The display is done via the partial view named '_post'. This partial view will be rendered once for every data item. In the view, one can access the current data item via variable $data. For more details, see itemView.

So in your context, $data is the Post being rendered.

Upvotes: 3

Related Questions