Cake 3博客教程错误使用newEntity时

时间:2015-01-19 07:25:37

标签: cakephp cakephp-3.0

这是发生的错误: Unable to find table class for current entity

这里是文章控制器的添加方法

public function add()
{
    $article = $this->Articles->newEntity();
    if ($this->request->is('post')) {
        $article = $this->Articles->patchEntity($article, $this->request->data);
        if ($this->Articles->save($article)) {
            $this->Flash->success(__('Your article has been saved.'));
            return $this->redirect(['action' => 'index']);
        }
        $this->Flash->error(__('Unable to add your article.'));
    }
    $this->set('article', $article);
}

这是add.ctp     

<h1>Add Article</h1>
<?php
    echo $this->Form->create($article);
    echo $this->Form->input('title');
    echo $this->Form->input('body', ['rows' => '3']);
    echo $this->Form->button(__('Save Article'));
    echo $this->Form->end();
?>

2 个答案:

答案 0 :(得分:1)

您需要升级CakePHP 3的安装。您遇到的是在发布第一个Releseas候选人之后出现的错误。要更新安装运行:

composer update

在您的app的根目录中,composer.json文件是。

答案 1 :(得分:0)

问题是因为实体! ,我刚刚创建了一个这样的实体文件:

<?php
namespace App\Model\Entity;

use Cake\ORM\Entity;

/**
 * User Entity.
 */
class Article extends Entity
{

}