postgresql - Cakephp 3 and Postgre add.cpt doesnt work id_parent -


i'm trying create easy page on cakephp 3 using postgresql. not understand problem: create table "menus". when add new instance (add.cpt) parent field empty cant add parent. it's generated command "cake bake menus".

thx :(

view

<div class="actions columns large-2 medium-3">     <h3><?= __('actions') ?></h3>     <ul class="side-nav">         <li><?= $this->html->link(__('list menus'), ['action' => 'index']) ?></li>     </ul> </div> <div class="menus form large-10 medium-9 columns">     <?= $this->form->create($menu); ?>     <fieldset>         <legend><?= __('add menu') ?></legend>         <?php             echo $this->form->input('name');             echo $this->form->input('parent_id');         ?>     </fieldset>     <?= $this->form->button(__('submit')) ?>     <?= $this->form->end() ?> </div> 

model

public function initialize(array $config) {     $this->table('menus');     $this->displayfield('name');     $this->primarykey('id');     $this->addbehavior('timestamp');     $this->belongsto('parentmenus', [         'classname' => 'menus',         'foreignkey' => 'parent_id'     ]);     $this->hasmany('childmenus', [         'classname' => 'menus',         'foreignkey' => 'parent_id'     ]); } 

controller

public function add() {     $menu = $this->menus->newentity();     if ($this->request->is('post')) {         $menu = $this->menus->patchentity($menu, $this->request->data);         if ($this->menus->save($menu)) {             $this->flash->success('the menu has been saved.');             return $this->redirect(['action' => 'index']);         } else {             $this->flash->error('the menu not saved. please, try again.');         }     }     $parentmenus = $this->menus->parentmenus->find('list', ['limit' => 200]);     $this->set(compact('menu', 'parentmenus'));     $this->set('_serialize', ['menu']);  } 

table menus

create table menus (   id serial not null,   name character varying(255),   created timestamp time zone,   modified time time zone,   parent_id integer,   constraint menus_pkey primary key (id),   constraint menus_parent_id_fkey foreign key (parent_id)       references menus (id) match simple       on update no action on delete no action ) 

either rename view variable $parentmenus $parents or in view change

echo $this->form->input('parent_id'); 

to

echo $this->form->input('parent_id', ['options' => $parentmenus]); 

Comments

Popular posts from this blog

javascript - gulp-nodemon - nodejs restart after file change - Error: listen EADDRINUSE events.js:85 -

Fatal Python error: Py_Initialize: unable to load the file system codec. ImportError: No module named 'encodings' -

javascript - oscilloscope of speaker input stops rendering after a few seconds -