I Am Digging Yii Demo -- Blog

Hi All.

I am digging demo-project blog

I don’t understand this piece of code $data->url in file blog/protected/views/post/_view.php

<?php echo CHtml::link(CHtml::encode($data->title), $data->url); ?>

How did object $data get it’s property “url”?

I understand that it’s property “title” is a field from form or table. But I wonder about “url”

Hi tonny

the file _view.php is rendered by the index.php view trough the widget CListView. Open the file and you will see it.

So this widget call the code of _view.php foreach item of $dataProvider and pass a variable called $data that is an object with variables of Model "Post". The Model "Post" (open the /protected/models/post.php) has a function called getUrl

According of setter and getter of Yii, each function with name getVar1 or setVar1 is accessed by "Var1".


So the echo CHtml::link('Permalink', $data->url); 

is the same with

echo CHtml::link('Permalink', $data->getUrl());

Great!!! Thanks, KonApaz)