[英]Phalcon model is not recognizing AUTO_INCREMENT table column
The current table Structure is: 当前表的结构为:
+---------------+------------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+---------------+------------------+------+-----+---------+----------------+
| id | int(10) unsigned | NO | PRI | NULL | auto_increment |
| title | varchar(25) | NO | UNI | NULL | |
| content | varchar(500) | NO | | NULL | |
+---------------+------------------+------+-----+---------+----------------+
Model: 模型:
<?php
namespace Com\Models;
use Phalcon\Mvc\Model;
use Phalcon\Mvc\Model\Validator\Uniqueness;
class Articles extends Model
{
/**
*
* @var integer
*/
public $id;
/**
*
* @var string
*/
public $title;
/**
*
* @var string
*/
public $content;
/**
* Returns table name mapped in the model.
*
* @return string
*/
public function getSource()
{
return 'articles';
}
/**
* Allows to query a set of records that match the specified conditions
*
* @param mixed $parameters
* @return Articles[]
*/
public static function find($parameters = null)
{
return parent::find($parameters);
}
/**
* Allows to query the first record that match the specified conditions
*
* @param mixed $parameters
* @return Articles
*/
public static function findFirst($parameters = null)
{
return parent::findFirst($parameters);
}
Upon saving data from controller, I am receiving this error: id is required
从控制器保存数据后,我收到此错误:
id is required
EDIT 编辑
Here is the snippet for the save method: 这是save方法的代码段:
$article = new Articles();
$article->title = $this->request->getPost('title', 'striptags');
$article->content = $this->request->getPost('content');
if (!$article->save()) {
$this->flash->error($article->getMessages());
} else {
$this->flash->success("Article created.");
Tag::resetInput();
}
I've never had a problem with auto increment fields and Phalcon. 我从来没有自动增量字段和Phalcon的问题。 Only thing I can suggest is setting default to AUTO_INCREMENT
我只能建议将默认设置为AUTO_INCREMENT
delete cache file 删除缓存文件
ex. 例如 "~\\cache\\metaData\\meta-bds_models_yourmodel-your_model.php"
“〜\\ cache \\ metaData \\ meta-bds_models_yourmodel-your_model.php”
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.