matthuisman Posted May 11, 2013 Share Posted May 11, 2013 Hi, Having a strange issue working through the Yii book CMS example. So. I will empty all tables then login as admin. I can then add a new user fine. user_id = 1. If I then try to add a page/comment/file, and input a user_id of 1, it returns "User "1" is invalid." The 'exist' validation is failing even though there is a user with user_id of 1. Strangely, this only happens if there are no rows in the 'page' table. If i manually add a row to the 'page' table then I can add pages from then on not a problem. But, if I go and delete the pages and then try add a page - error comes back. So, the fault only happens if the table is empty. Any help would be apperciated. Thanks, Matt Link to comment Share on other sites More sharing options...
matthuisman Posted May 13, 2013 Author Share Posted May 13, 2013 Update: Fixed the issue by using: array('user_id', 'exist', 'attributeName'=>'id', 'className'=>'User'), Did a bit of debugging, the SQL yii was using before using the above was "SELECT 1 FROM `page` `t` WHERE `t`.`user_id`=:ycp0 LIMIT 1" Now, with the above it uses "SELECT 1 FROM `user` `t` WHERE `t`.`id`=:ycp0 LIMIT 1" So, think this may be a mistake in the book? Thanks, Matt Link to comment Share on other sites More sharing options...
matthuisman Posted May 13, 2013 Author Share Posted May 13, 2013 Also, same fix for Comments.php model ' array('user_id', 'exist', 'attributeName'=>'id', 'className'=>'User'),array('page_id', 'exist', 'attributeName'=>'id', 'className'=>'Page'), ' Link to comment Share on other sites More sharing options...
scribbly Posted September 4, 2013 Share Posted September 4, 2013 Thanks matthuisman... I had that problem in Chapter 5 too. Found docs helpful: http://www.yiiframework.com/doc/api/1.1/CExistValidator Though, I'm confused if the source code works, why isn't my code working? Larry?? Link to comment Share on other sites More sharing options...
Larry Posted September 4, 2013 Share Posted September 4, 2013 I didn't have this problem while I was writing that section, but I'll check into it. An issue is that the CMS example is used for various demonstration purposes, so it's not a complete thing (until I do that in Part 4 of the book), which can lead to problems depending upon what you have or have not implemented. Link to comment Share on other sites More sharing options...
Recommended Posts