George
George

Reputation: 47

What is the“'condition'=>'project_id=:projectId',”?what is the meaning of “:”?

I don’t know What is the“'condition'=>'project_id=:projectId',”?what is the meaning of “:”? In another word why we should put the “:” in front of the projectId. the code is as below.

public function actionIndex()
    {
        $dataProvider=new CActiveDataProvider('Issue',array(
            'criteria'=>array(
                'condition'=>'project_id=:projectId',
                'params'=>array(':projectId'=>$this->_project->id),
            ),
        ));

Upvotes: 0

Views: 64

Answers (1)

Virginia
Virginia

Reputation: 737

The way I understand your code snippet, this has to do with escaping query parameters / prepared SQL statements. This prevents SQL injection. In your example, :projectId in condition is another way of saying "Please replace this :projectId with the escaped value of :projectId ($this-_project->id) from params when executing this query".

Upvotes: 1

Related Questions