在CakePHP中创建新页面

时间:2010-07-16 17:22:10

标签: cakephp

我创建了这个文件,甚至将代码添加到了items_controller文件中(我学习了这个文件,因为不必在常规PHP中进行),但仍然收到一条消息,说明找不到新页面。

http://neighborrow.com/items/create/

错误必须在items_controller文件中,因为它在调试模式下工作,但当我列出一个项目时,它显示我从items / add页面复制的确认消息,即使我为create编辑了它: / p>

    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));
                    }
                }
            }
        }
    }

1 个答案:

答案 0 :(得分:3)

创建新页面后,您需要将debug设置为&gt; 0,否则它将不会重新生成缓存,并且缓存的文件将不会有新操作。您也可以手动删除缓存(删除app / tmp / cache下的文件,离开我的头顶)。将其设置为“1”将不会执行大多数调试工作,但会重新生成模型文件。因此,当您设置debug以查看它时,它会重新生成缓存的文件并运行。

所以新规则:当您创建新的操作或模型时,请先将debug设置为1或清除缓存,然后再尝试使用它。