cakephp - how add more function in same view page? -
this 1 of controller app\controller\dashboardscontroller.php here patientslist controller
<?php class dashboardscontroller extends appcontroller { public $components = array('session'); public function index() { $this-> loadmodel('patientslist'); $this->set('posts', $this->patientslist->find('all', array('conditions' => array('patientslist.user_id' => $this->auth->user('id'))))); } public function view($id) { $this-> loadmodel('patientslist'); if (!$id) { throw new notfoundexception(__('invalid post')); } $post = $this->patientslist->findbyid($id); if (!$post) { throw new notfoundexception(__('invalid post')); } $this->set('post', $post); } public function add() { $this-> loadmodel('patientslist'); if ($this->request->is('post')) { //added line $this->request->data['patientslist']['user_id'] = $this->auth->user('id'); if ($this->patientslist->save($this->request->data)) { $this->session->setflash(__('your post has been saved.')); return $this->redirect(array('action' => 'index')); } } } /* public function add() { if ($this->request->is('post')) { $this->post->create(); if ($this->post->save($this->request->data)) { $this->session->setflash(__('your post has been saved.')); return $this->redirect(array('action' => 'index')); } $this->session->setflash(__('unable add post.')); } } */ public function edit($id = null) { $this-> loadmodel('patientslist'); if (!$id) { throw new notfoundexception(__('invalid post')); } $post = $this->patientslist->findbyid($id); if (!$post) { throw new notfoundexception(__('invalid post')); } if ($this->request->is(array('patientslist', 'put'))) { $this->patientslist->id = $id; if ($this->patientslist->save($this->request->data)) { $this->session->setflash(__('your post has been updated.')); return $this->redirect(array('action' => 'index')); } $this->session->setflash(__('unable update post.')); } if (!$this->request->data) { $this->request->data = $post; } } public function delete($id) { $this-> loadmodel('patientslist'); if ($this->request->is('get')) { throw new methodnotallowedexception(); } if ($this->patientslist->delete($id)) { $this->session->setflash( __('the post id: %s has been deleted.', h($id)) ); return $this->redirect(array('action' => 'index')); } } public function isauthorized($user) { $this-> loadmodel('patientslist'); // registered users can add posts if ($this->action === 'add') { return true; } // owner of post can edit , delete if (in_array($this->action, array('edit', 'delete'))) { $postid = $this->request->params['pass'][0]; if ($this->patientslist->isownedby($postid, $user['id'])) { return true; } }// return parent::isauthorized($user); } }
here view app\view\dashboards\index.ctp
<div id="tabs"> <ul> <li><a href="#tabs-1">myprofile</a></li> <li><a href="#tabs-2">patients</a></li> <li><a href="#tabs-3">list</a></li> </ul> <div id="tabs-1"> </div> <div id="tabs-2"> <p><?php echo $this->html->link('add patient', array('action' => 'add')); ?></p> <table> <tr> <th>patient's name</th> <th>address</th> <th>email-id</th> <th>mobile</th> <th>age</th> <th>gender</th> <th>actions</th> <th>created</th> </tr> <!-- here's loop through our $posts array, printing out post info --> <?php foreach ($posts $post): ?> <tr> <td><?php echo $this->html->link( $post['patientslist']['patients_name'], array('action' => 'view', $post['patientslist']['id']) ); ?></td> <td> <?php echo $post['patientslist']['address']; ?> </td> <td> <?php echo $post['patientslist']['email']; ?> </td> <td> <?php echo $post['patientslist']['mobile']; ?> </td> <td> <?php echo $post['patientslist']['age']; ?> </td> <td> <?php echo $post['patientslist']['gender']; ?> </td> <td> <?php echo $this->form->postlink( 'delete', array('action' => 'delete', $post['patientslist']['id']), array('confirm' => 'are sure?') ); ?> <?php echo $this->html->link( 'edit', array('action' => 'edit', $post['patientslist']['id']) ); ?> </td> <td> <?php echo $post['patientslist']['created']; ?> </td> </tr> <?php endforeach; ?> </table> </div> <div id="tabs-3"> </div> </div>
here have display same tab add, edit, delete in same page how possible?
Comments
Post a Comment