如何在同一个视图页面添加更多功能?

时间:2014-03-10 05:55:08

标签: cakephp

这是我的控制器之一 应用\控制器\ DashboardsController.php  这里Patientslist是我的另一个控制者

<?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 this 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 to add your 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 to update your 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 with id: %s has been deleted.', h($id))
        );
        return $this->redirect(array('action' => 'index'));
    }
}
public function isAuthorized($user) {
     $this-> loadModel('Patientslist');
    // All registered users can add posts
    if ($this->action === 'add') {
        return true;
    }

    // The owner of a post can edit and delete it
    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);
}
}

此处查看 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 where we loop through our $posts array, printing out post info -->

    <?php foreach ($posts as $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 you 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>

在这里我必须显示相同的标签,以便在同一页面中添加,编辑,删除它们的可能性如何?

0 个答案:

没有答案