Yii Framework Forum: I Am Digging Yii Demo -- Blog - Yii Framework Forum

Jump to content

Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

I Am Digging Yii Demo -- Blog demo question Rate Topic: -----

#1 User is offline   tonny 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 25-December 12

Posted 25 December 2012 - 07:36 AM

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"
0

#2 User is offline   KonApaz 

  • Elite Member
  • PipPipPipPipPip
  • Yii
  • Group: Members
  • Posts: 1,327
  • Joined: 21-February 11
  • Location:Greece

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".

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

Yii is the best php framework in the world!
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
0

#3 User is offline   tonny 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 11
  • Joined: 25-December 12

Posted 27 December 2012 - 12:33 PM

View PostKonApaz, 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".

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



Great!!! Thanks, KonApaz)
0

Share this topic:


Page 1 of 1
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users