我使用Phalcon Framework和PostgreSQL
我尝试将数组插入数据库列类型:varchar[]
:
array(4) { [0]=> string(1) "1" [1]=> string(1) "6" [2]=> string(1) "9" [3]=> string(2) "12" }
但是得到以下错误:
SQLSTATE [HY093]:参数号无效:参数未定义
请帮我解决这个问题
答案 0 :(得分:0)
这是我的模特:
<?php
namespace App\Models;
use Phalcon\Mvc\Model;
use Phalcon\Validation;
use Phalcon\Validation\Validator\Uniqueness;
class Document extends Model
{
public $id;
public $relatedocument;
public function getSource()
{
return "document";
}
=====表格==
<?php
namespace App\Modules\Backend\Forms;
use Idoc\Models\Document;
use Phalcon\Forms\Form;
use Phalcon\Forms\Element\Select;
class DocumentForm extends Form
{
public function initialize($entity = null, $options = null)
{
$data = Document::find();
$this->add(new Select('relatedocument[]', $data, [
'using' => [
'id',
'name'
],
'useEmpty' => true,
'emptyText' => '....',
'multiple' => 'multiple',
'class' => 'form-control search-select'
]));
}
=====的addAction ==
public function addAction()
{
if ($this->request->isPost()) {
$doc = new Document();
$doc->relatedocument = $this->request->getPost('relatedocument');
if (!$doc->save()) {
$this->flash->error($doc->getMessages());
} else {
$this->flash->success("Văn bản đã được tạo");
Tag::resetInput();
}
}
$this->view->form = new DocumentForm(null);
}