私は記事とタグでブログを作ろうとしますが、何らかの理由で記事作成時にタグが保存されません。 私は公式のケーキのブログからいくつかのアイデアに従っていたが、ここでは運がない。私が間違っていると私は見ていないかもしれない。キーワードのCakephp 3のセーブアソシエーションが動作しない
テーブル
CREATE TABLE `keywords` (
`id` int(11) NOT NULL,
`article_id` int(11) DEFAULT NULL,
`tag` varchar(255) DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=latin1;
表モデル キーワード:
class KeywordsTable extends Table
{
......................
public function initialize(array $config)
{
parent::initialize($config);
$this->table('keywords');
$this->displayField('id');
$this->primaryKey('id');
$this->belongsTo('Article', [
'foreignKey' => 'article_id',
'joinType' => 'INNER'
]);
}
....................
}
条
class ArticleTable extends Table
{
public function initialize(array $config)
{
parent::initialize($config);
$this->table('article');
$this->displayField('id');
$this->primaryKey('id');
$this->addBehavior('Timestamp');
$this->belongsTo('Users', [
'foreignKey' => 'user_id',
'joinType' => 'INNER'
]);
$this->hasMany('Keywords', [
'foreignKey' => 'article_id'
]);
}
......................................
}
そして、ここでは私のコントローラである:
public function add()
{
//$this->autoRender = false;
$article = $this->Article->newEntity();
if ($this->request->is('post')) {
$article = $this->Article->patchEntity($article, $this->request->data, ['associated'=>['Keywords']]);
echo "<pre>";
print_r($this->Article->save($article));
die();
}
}
そして、このいずれかが、私は感謝します私を助けることができるのであれば、私の形で私が使用するコード
<?= $this->Form->input('article[keywords][]', ['label'=>false, 'class' => 'form-control', 'placeholder' => 'keywords', 'templates' => ['inputContainer' => '{{content}}']]); ?>
です。