Yii Framework Forum: $this->getProject()->id vs $model->project_id - Yii Framework Forum

Jump to content

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

$this->getProject()->id vs $model->project_id End of iteration 6

#1 User is offline   Enrico Pallazzo 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 3
  • Joined: 26-August 12

Posted 04 September 2012 - 04:42 AM

When I look at /views/issue/create.php I see this code:

$this->menu=array(
	array('label'=>'List Issue', 'url'=>array('index', 'pid'=>$model->project_id)),
	array('label'=>'Manage Issue', 'url'=>array('admin', 'pid'=>$model->project_id)),
);


Which uses: 'pid'=>$model->project_id

When I look at /views/issue/index.php I see this code:

$this->menu=array(
	array('label'=>'Create Issue', 'url'=>array('create', 'pid'=>$this->getProject()->id)),
	array('label'=>'Manage Issue', 'url'=>array('admin', 'pid'=>$this->getProject()->id)),
);


Which uses: 'pid'=>$this->getProject()->id

Why this difference? And why can't I use 'pid'=>$model->project_id in /views/issue/index.php?

Somehow it doesn't look very consistent to me.
0

#2 User is offline   Kostas Apazidis (KonApaz) 

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

Posted 12 December 2012 - 11:10 AM

Hi Enrico

It depends

If you mentioned in controller action in the first case the
$model->project_id = $this->_project->id;
set the project_id and pass $mode in the view, so $model->project_id is available in view file

In the second case the view access this id directly from controller ($this->getProject()->id)

So there is no difference between these approaches! The author reveal to you a few ways to do that :)
Yii is the best php framework in the world!
It is also powerful and flexible for large scale websites
find our demo Yii extension on www.webkit.gr
Is it post useful? please v++ ;)
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