php - CActiveDataProvider not resolving params in criteria


I'm following along with Agile Web Application Development with Yii 1.1 and PHP5, working on the "TrackStar" project. For the life of me I can't understand where my problem is. I'm getting the Exception:

CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: parameter was not defined. The SQL statement executed was: SELECT COUNT(*) FROMtbl_issuet WHERE project_id=:projectId

It appears (to this noob's interpretation) that the params in my CActiveDataProvider is some how not resolving in the criteria as in the view:

(in /protected/controllers/ProjectController.php)

55         public function actionView()
56         {
57             $issueDataProvider = new CActiveDataProvider('Issue', array(
58                 'criteria' => array(
59                     'condition' => 'project_id=:projectId',
60                     'params' => array(':projectId=' => $this->loadModel()->id),
61                 ),
62                 'pagination' => array( 
63                     'pageSize' => 1,
64                 ),      
65             )); 
66             $this->render('view',array(
67                     'model'=>$this->loadModel(),
68                     'issueDataProvider' => $issueDataProvider,
69             ));
70         }

I checked my code against a github repo and I couldn't find any differences anywhere. Is there something straightforward I'm missing here without having to post all of my code (and have somebody actually look through it)?




It looks you have an error in params of your criteria. (= after :projectId). Right statement is

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

Params array is list of query parameter values indexed by parameter placeholders. For example, array(':name'=>'Dan', ':age'=>'31').

People are also looking for solutions to the problem: How can I disable PHP's "easter egg" URLs?


Didn't find the answer?

Our community is visited by hundreds of web development professionals every day. Ask your question and get a quick answer for free.

Ask a Question

Write quick answer

Do you know the answer to this question? Write a quick response to it. With your help, we will make our community stronger.

Similar questions

Find the answer in similar questions on our website.