:projectId and :projectID


(Alan12341234) #1

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.


(Maurizio Domba Cerin) #2

To understand the placeholders in a select read this - http://www.php.net/manual/en/pdostatement.bindparam.php

Basicaly :projectid is a placeholder (not a variable) that is replaced with a value that you assign to it with ‘params’


(Alan12341234) #3

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


(Maurizio Domba Cerin) #4

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… :)


(Alan12341234) #5

I see,

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

this (http://www.php.net/manual/en/pdostatement.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.