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(*) FROM
tbl_issue
t
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)?
Answer
Solution:
It looks you have an error in params of your criteria. (
=
after :projectId). Right statement isParams array is list of query parameter values indexed by parameter placeholders. For example, array(':name'=>'Dan', ':age'=>'31').