Yii Framework Forum: :projectId and :projectID - Yii Framework Forum

Jump to content

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

:projectId and :projectID Please help me to understand

#1 User is offline   Alan Cheung 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 22-December 10

Posted 23 December 2010 - 10:43 PM

One Page 125:

public $fixtures=array( 'projects'=>'Project', 'users'=>'User', 'projUsrAssign'=>':tbl_project_user_assignment', );

It says using ":" to indicate that this is a database table, and not an AR model class. - I understand


On Page 129:

$issueDataProvider=new CActiveDataProvider('Issue', array( 'criteria'=>array(
'condition'=>'project_id=:projectId',
'params'=>array(':projectId'=>$this->loadModel()->id), ),

There is no explanation why ":" is being used. Could someone please explain this to me? I'm very confused. The only "projectId" variable is found in the filter function of IssueController. I'm not sure if :projectId is referencing that variable.


On Page 144, there is a line:

$criteria->condition='project_id=:projectID';

I'm not sure if this is a typo of :projectId or its another reference to some other places.
The code seems to work fine but I'm very confused.

Please help. Thank you.
0

#2 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 24 December 2010 - 02:23 AM

To understand the placeholders in a select read this - http://www.php.net/m...t.bindparam.php

Basicaly :projectid is a placeholder (not a variable) that is replaced with a value that you assign to it with 'params'
Find more about me.... btw. Do you know your WAN IP?
0

#3 User is offline   Alan Cheung 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 22-December 10

Posted 24 December 2010 - 04:52 AM

I can understand the link you gave me but still quite confused in the context of the book....
0

#4 User is offline   Maurizio Domba Cerin 

  • Yii - Yesss It Is !!!
  • Yii
  • Group: Yii Dev Team
  • Posts: 4,359
  • Joined: 12-October 09
  • Location:Croatia

Posted 24 December 2010 - 05:02 AM

Can you explain what you don't understand...

As per your question.. .you did not understand what is :projectid... and you thouth it's a variable...

So if you now understand the concept of binding... then you know that on this line

'condition'=>'project_id=:projectId',


:projectId is just a placeholder... it does not have any value for now... a real value will be binded here...

and this line

'params'=>array(':projectId'=>$this->loadModel()->id), ),


Say that the value of $this->loadModel()->id should be placed instead of the placeholder :projectId

Hope it's clear now... :)
Find more about me.... btw. Do you know your WAN IP?
1

#5 User is offline   Alan Cheung 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 5
  • Joined: 22-December 10

Posted 24 December 2010 - 11:12 AM

I see,

However, what would replace the place holder of :projectID ?

this (http://www.php.net/m...t.bindparam.php) suggests that a variable name same as the place holder will replace it's value?!

Is that the same in this case?

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