【发布时间】:2016-04-14 21:27:36
【问题描述】:
当前表结构为:
+---------------+------------------+------+-----+---------+----------------+
| 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
编辑
这里是保存方法的sn-p:
$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();
}
【问题讨论】:
-
用保存方法更新了问题。
-
您是否正确配置了
modelsMetadata服务? -
是的,配置正确。问题仅限于
Articles模型。 -
你解决了这个问题吗?
-
@FazalRasel 不,这很奇怪,我改用 NoSQL 解决方案。