【发布时间】:2012-01-02 19:56:30
【问题描述】:
我需要 ATK4 CRUD 方面的帮助。我已经使用 Agile Toolkit 4.1.3 为项目构建了一个后端。 我有以下型号:
class Model_Product extends Model_Table
{
public $entity_code = 'product';
function init()
{
parent::init();
$this->addField('category_id')->refModel('Model_Category')->mandatory(true);
$this->addField('name')->mandatory(true);
$this->addField('picture_id')->refModel('Model_Picture')->mandatory(true);
$this->addField('short_description')->mandatory(true);
$this->addField('description')->type('text')->mandatory(true);
$this->addField('uploaded_at')->type('datetime');
$this->addField('price')->type('int')->mandatory(true);
$this->addField('quantity')->type('int')->mandatory(true);
$this->addField('status')->datatype('list')
->listData(array(
'enabled'=>'Enabled',
'disabled'=>'Disabled',
))
->defaultValue('enabled');
}
}
页面:
<?php
class page_index extends Page {
function init(){
parent::init();
$page=$this;
$tabs = $page->add('Tabs');
$tabs->addTab('Product')->add('CRUD')->setModel('Product');
....
在我的本地主机上,所有 CRUD 功能都可以正常工作,但是在我将文件上传到网络服务器后,当我尝试添加新产品时,我收到了这个错误:
`AJAX 响应中的错误:SyntaxError:无效的 XML 属性值 SQL异常
无法执行查询:插入产品(category_id、name、picture_id、short_description、description、uploaded_at、price、quantity、status)值( NULL, 'as', NULL, '', '', NULL, 2500, 25, '启用')
最后查询:
插入产品(category_id,name,picture_id,short_description,description,uploaded_at,price,quantity,status)值(NULL,'as',NULL, '', '', NULL, 2500, 25, '启用')
MySQL错误:
列“category_id”不能为空`
奇怪的是,查询中的缺失值在 crud 表单中可见,但从未出现在查询中。附加信息:在 Model_Picture 中,我使用 varchar id 字段而不是 autoincrement int 但再次在 localhost 上一切正常。
谢谢!
【问题讨论】:
-
我在这里添加了一个与您的案例有关的键盘示例:codepad.agiletoolkit.org/stackcrud,即使这些字段是强制性的,敏捷工具包也允许将它们保留为空值。我对这个问题感到困惑,你确定桌子是一样的吗?可以删除并重新创建表吗?
-
我删除然后用sqldump再次添加表,但错误仍然存在。我什至尝试了上面的查询,将 NULL 和缺失值更改为有意义的值并且它有效。使用 Model_Category 的 Crud 页面添加类别有效。如果我找不到解决方案,我会在周末从头开始重写整个东西。
标签: php frameworks atk4