我正在尝试构建一个应用程序来保存cakephp3中的多个记录。
现在,我意识到要创建控制器和视图。 但验证和Flash消息不起作用。 请告诉我如何使用验证消息和闪存消息。
控制器:
public function addition5(){
$this->ViewBuilder()->layout('auth');
$articles = TableRegistry::get('articles');
$entities = $articles->newEntities($this->request->data());
if($this->request->is('post')){
$articles->connection()->transactional(function () use ($articles, $entities) {
foreach ($entities as $entity) {
$articles->save($entity, ['atomic' => false]);
}
});
//var_dump($entities);
}
$this->set(compact('articles'));
$this->set('_serialize', ['articles']);
}
查看:
echo $this->Form->create($articles,["class" => "article_form"]);
for($i = 0; $i < 5;$i++){
$j = $i + 1;
echo '<h2 class="add5">add articles('.$j.'/5)</h2>';
echo $this->Form->hidden($i.'.user_id',['value' => h($this->request->session()->read('Auth.User.id'))]);
echo $this->Form->input($i.'.title',['label' => 'title','placeholder' => 'title']);
echo $this->Form->input($i.'.comment',['label' => 'comment','placeholder' => 'comment']);
}
echo $this->Form->button('submit',["class" => "ok"]);
echo $this->Form->end();