Creating new pages in CakePHP
I created the file and even added the code to the items_controller file (which I learned since not having to do it in regular PHP) but still getting a message that the new page is not found.
http://neighborrow.com/items/create/
The error must be in the items_controller
file because it's working in debug mode, but when I list an item it's showing the confirm message I copied from the items/add page even though I edited it for create:
function create()
{
if(!empty($this->data))
{
if (!empty($this->data))
{
$user_error = false;
$this->Item->create();
if($this->Auth->user())
{
$user_id = $this->Auth->User('id');
}
else
{
if (!$user_id = $this->Item->User->is_user($this->data['Item']['user_email']))
{
$email = $this->data['Item']['user_email'];
// Create Password
$raw_password = $this->PasswordHelper->generatePassword();
// Has Password
$hashed_password = $this->Auth->password($raw_password);
// Add User
if (!$user_id = $this->Item->User->add_basic($email, $hashed_password))
$user_error = true;
// Login the User
$this->Auth->login(array('开发者_开发技巧email' => $email, 'password' => $hashed_password));
// Send Registration Email
$this->Email->send_registration_email($email, $raw_password);
}
}
if(!$user_error)
{
$this->data['Item']['user_id'] = $user_id;
$this->data['Item']['approved'] = 1;
if ($this->Item->save($this->data))
{
$this->Session->setFlash('Congratulations on your first listing! After we review it to make sure it is rentable, we will send you your free profile where you can list, promote, and rent up to nine more items. Feel free to share you new listing right away! <a name="fb_share" type="button_count" href="http://www.facebook.com/sharer.php">Share</a><script src="http://static.ak.fbcdn.net/connect.php/js/FB.Share" type="text/javascript"></script>.');
$this->redirect(array('controller' => 'items', 'action' => 'view', $this->Item->id));
}
}
}
}
}
After creating a new page, you need to set debug to >0, because otherwise it won't regenerate the cache, and the cached file won't have the new action. You can also just delete the cache manually (delete the files under app/tmp/cache, off of the top of my head). Setting it to '1' won't do most debug stuff, but will regenerate model files. So when you set debug to look at it, it re-generated the cached file and worked.
So new rule: when you create new actions or models, set debug to 1 or clear the cache before trying to do anything with it.
精彩评论