Jump to content
Larry Ullman's Book Forums
Sign in to follow this  
aguskianto

Beforevalidate() Function Is Not Working

Recommended Posts

Dear All,

 

I've been following the book until I reach Chapter 5 Page 101:

 

# protected/models/Page.phpprotected function beforeValidate(){            if(empty($this->user_id))        {               $this->user_id = Yii::app()->user->id;        }
        return parent::beforeValidate();}

The problem that I found when I try to create Page:

 

CDbCommand failed to execute the SQL statement: SQLSTATE[HY000]: General error: 1366 Incorrect integer value: '' for column 'user_id' at row 1. The SQL statement executed was: INSERT INTO `page` (`live`, `user_id`, `title`, `content`, `date_updated`, `date_published`) VALUES (:yp0, :yp1, :yp2, :yp3, NOW(), :yp4)

 

Is there something that I miss?

 

Regards,

 

Agus Kianto

Share this post


Link to post
Share on other sites

I think I found something interesting. I don't find Username Admin Password Admin on my User table. This username is used to accress create page.

 

But this username is not listed on the table:

 

1    Test

2    Someones

3    Some Author

4    Another Author

5    Administrator

6    Another Admin

7    Jane

8    John

9    Curly

10  Moe

11  Larry

12  Vlad

13  testing

14  Latest Test

15  Joe Public

16  Jane Public

 

Is there any connection between those two?

Share this post


Link to post
Share on other sites

The default site generated uses "demo" and "admin" as possible usernames. In the book I also create database users (listed above). You'll need to decide which you're using. If you're using the latter, then you can log in using those values and you'll end up using that user ID when the page is created, thanks to the beforeValidate() method.

Share this post


Link to post
Share on other sites

Well, I do understand that you create that user table. But, can I use that already in this chapter? Or, should I wait for later chapter for this things to work?

 

One thing for sure, I try to login using those user in the user table but I got some: "Incorrect username or password" error.

 

So, once again I ask: can this user in the table be used in this chapter already? or should I wait for another chapter.  :rolleyes:

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...