定义模型中的实体


Defining entity in model

我正在尝试做一个在Jobeet教程(http://agiletoolkit.org/learn/tutorial/jobeet/day3)中提到的CRUD。我还添加了一个generate.php内部页面目录与链接中提到的代码。当我尝试通过http://localhost/atk4.1.2/?page=generate通过浏览器访问它时,我得到以下错误,

Exception_ForUser
You should call parent::init() when you override it

Additional information: 
 - object_name: gift_project_generate
 - class: page_generate

我还在页面目录中添加了一个名为crud.php的页面,其中包含以下内容,其内容如下:

<?php
class page_crud extends Page{
    function init(){
        parent::init();
        $tabs=$this->add('Tabs');
        $tabs->addTab('Gifts')->add('CRUD')->setModel('Gift');
    }
}
下面是Model目录下的Gift.php,
<?php
class Model_Gift extends Model_Table {
    function init(){
        parent::init();
        $this->addField('id');
        $this->addField('name')->type('text');
        $this->addField('url')->type('text');
    }
}

现在,当我尝试通过http://localhost/atk4.1.2/?page=crud访问crud页面时,我看到以下错误,

Exception_InitError
You should define entity code for Model_Gift

C:'xampp'htdocs'atk4.1.2'atk4'lib'BaseException.php:37

但是数据库已经有一个名为gift的表,并且$this->dbConnect();在Frontend.php中没有注释。

我错过了什么吗?

将此添加到您的模型定义:

public $enity_code='gift';

这应该与SQL中的表名完全相同。

关于init()没有被调用的另一个错误是一个bug: https://github.com/atk4/atk4/issues/22