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"
Page 1 of 1
I Am Digging Yii Demo -- Blog demo question
#2
Posted 25 December 2012 - 01:45 PM
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".
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());
#3
Posted 27 December 2012 - 12:33 PM
KonApaz, on 25 December 2012 - 01:45 PM, said:
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".
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)
Share this topic:
Page 1 of 1

Help













