[SOLVED] Ch 6 Issue Search issue

I’ve just [finally] finished chapter 6 (and enjoying the ride)… but the search functionality has disappeared from my issues page.

Projects works, but issues keeps displaying all records regardless of the search criteria (ie id=1 I’d expect to return one record).

Any hints how I can track down the problem??

Thanks BTW to all the helpful posters here about the book: made it much more possible!!

I’ve now downloaded the code and there is no difference (apart from edits in future chapters), but the searh does not filter the records.

Would really like to understand how this has happened and how to fix??

Please take a look at the Issue::search() method in the model class file Issue.php. Towards the end of that method, there may be a typo that results in all previously set criteria conditions being overwritten, rather than appended to. If you change this:


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

to


$criteria->addCondition('project_id=:projectID');

It should address your search issues you are experiencing.

Thanks Jeff. I actually hooked onto this thread which sorted out the problem.

I meant to mention in this thread too, but I got too excited and finished the book!! Loved it by the way, I’m now “re-doing it” for my own project (which is different).

i’ve made the change but now it fire an sql error


CDbCommand failed to execute the SQL statement: SQLSTATE[HY093]: Invalid parameter number: number of bound variables does not match number of tokens. The SQL statement executed was: SELECT COUNT(*) FROM `tbl_issue` `t` WHERE (project_id LIKE :ycp0) AND (project_id=:projectID)

i’m using Yii 1.1.10

So I found a solution before posting the prob, I guess it’s good but not so sure,

Replaced (2 lines)


$criteria->addCondition('project_id=:projectID');

$criteria->params = array(':projectID' => $this->project_id);



to 1 line


$criteria->addColumnCondition( array( 'project_id' => $this->project_id) );

( ./yii-docs-1.1.8.r3324/api/CDbCriteria.html#addColumnCondition-detail )