Phalcon模型无法识别AUTO_INCREMENT表列

时间:2016-01-10 14:57:29

标签: php mysql model phalcon

当前表格结构为:

+---------------+------------------+------+-----+---------+----------------+
| 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    |                |
+---------------+------------------+------+-----+---------+----------------+

型号:

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

从控制器保存数据后,我收到此错误:id is required

修改

以下是保存方法的代码段:

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

2 个答案:

答案 0 :(得分:0)

我从未遇到过自动增量字段和Phalcon的问题。 我唯一能建议的是将默认设置为AUTO_INCREMENT

答案 1 :(得分:0)

删除缓存文件

离。 &#34;〜\缓存\元数据\元bds_models_yourmodel-your_model.php&#34;