edit - Please help me to get the dynamic id of the record in the listing of the records in Cakephp 2.3.9 -


i used bake make cms of settings table.

it contains 3 fields.

column type null default id int(11) no
key varchar(10) no
value varchar(200) no

and have 3 records.

all create functionality working fine. delete , edit edit/delete first record.

for getting link...

i used following code in view file.

   foreach ($languages $language){      echo $this->html->link(__('edit'), array('action' => 'edit', $language['language']['id'])); ?>      echo $this->form->postlink(__('delete'), array('action' => 'delete', $language['language']['id']), null, __('are sure want delete # %s?', $language['language']['id']));  } 

i assigned following value languages variable controller.

   $this->language->recursive = 0;  $this->set('languages', $this->paginate());  

schema:

create table if not exists languages (     id int(11) not null auto_increment,     title varchar(30) not null,     slug enum('eng','rus') not null default 'eng',     symbol varchar(50) not null,     status enum('a','i','d') not null default 'a',     created_dt timestamp not null default current_timestamp,     modified_dt datetime not null, primary key (id),     unique key unique language code (slug),     key status (status) ) engine=innodb default charset=utf8 auto_increment=7 ; 

in controller following

public function edit($id = null) {     if (!$id) {           throw new notfoundexception(__('invalid edit id'));     }     $language = $this->language->find('first', array(           'conditions' => array(                   'language.id' => $id,            ),     ));      if (empty($language)) {            throw new badrequestexception(__('invalid data'));     }      if ($this->request->is('post') || $this->request->is('put')) {          if ($this->language->save($this->request->data()) {             $this->session->setflash(__('saved'));          } else {             $this->session->setflash(__('something went wrong'));          }     }      if (empty($this->request->data)) {         $this->request->data = $language;     } }  public function delete($id = null) {  $this->language->id = $id;  if (!$this->language->exists()) {      throw new notfoundexception(__('invalid language'));  }  $this->request->onlyallow('post', 'delete');  if ($this->language->delete()) {         $this->session->setflash(__('language deleted'));         $this->redirect(array('action' => 'index'));  }  $this->session->setflash(__('language not deleted'));  $this->redirect(array('action' => 'index')); } 

Comments

Popular posts from this blog

html - How to style widget with post count different than without post count -

How to remove text and logo OR add Overflow on Android ActionBar using AppCompat on API 8? -

javascript - storing input from prompt in array and displaying the array -