2016-12-26 37 views
0

私は病院管理システムでウェブサイトを作成しています。従業員が医者、医療スタッフ、または管理者のいずれであるかを指定するタイプの列を持つ従業員コントローラがあります。このページでは、「医師」というアクションがあります。このボタンをクリックすると、「ドクター」タイプの従業員が同じページでのみ返されます。コントローラとテンプレートにはどのような変更が必要ですか?Cakephpの同じページでクエリの結果を返します

Employeeテーブル:

<?php 
namespace App\Model\Table; 

use Search\Manager; 
use Cake\ORM\Query; 
use Cake\ORM\RulesChecker; 
use Cake\ORM\Table; 
use Cake\Validation\Validator; 

class EmployeeTable extends Table 
{ 
    public function initialize(array $config) 
    { 
     parent::initialize($config); 

     $this->table('employee'); 
     $this->displayField('Employee_ID'); 
     $this->primaryKey('Employee_ID'); 
     $this->addBehavior('Search.Search'); 
     $this->searchManager() 
      ->value('Employee_ID'); 
    } 

    public function validationDefault(Validator $validator) 
    { 
     $validator 
      ->allowEmpty('Employee_ID', 'create'); 

     $validator 
      ->requirePresence('Name', 'create') 
      ->notEmpty('Name'); 

     $validator 
      ->requirePresence('Address', 'create') 
      ->notEmpty('Address'); 

     $validator 
      ->date('DOB') 
      ->requirePresence('DOB', 'create') 
      ->notEmpty('DOB'); 

     $validator 
      ->allowEmpty('Contact'); 

     $validator 
      ->requirePresence('Gender', 'create') 
      ->notEmpty('Gender'); 

     $validator 
      ->numeric('Salary') 
      ->allowEmpty('Salary'); 

     $validator 
      ->allowEmpty('Category'); 

     $validator 
      ->requirePresence('Dept_No', 'create') 
      ->notEmpty('Dept_No'); 

     return $validator; 
    } 
} 

従業員コントローラー:

<?php 
namespace App\Controller; 

use App\Controller\AppController; 

class EmployeeController extends AppController 
{ 

    public function initialize() 
{ 
    parent::initialize(); 
    $this->loadComponent('Search.Prg', [ 
     'actions' => ['index'] 
    ]); 
} 

    public function index() 
    { 
     $employee = $this->paginate($this->Employee); 

     $this->set(compact('employee')); 
     $this->set('_serialize', ['employee']); 
     $query = $this->Employee 
     ->find('search', ['search' => $this->request->query]); 
    $this->set('patients', $this->paginate($query)); 
    } 

    public function view($id = null) 
    { 
     $employee = $this->Employee->get($id, [ 
      'contain' => [] 
     ]); 

     $this->set('employee', $employee); 
     $this->set('_serialize', ['employee']); 
    } 

    public function add() 
    { 
     $employee = $this->Employee->newEntity(); 
     if ($this->request->is('post')) { 
      $employee = $this->Employee->patchEntity($employee, $this->request->data); 
      if ($this->Employee->save($employee)) { 
       $this->Flash->success(__('The employee has been saved.')); 

       return $this->redirect(['action' => 'index']); 
      } else { 
       $this->Flash->error(__('The employee could not be saved. Please, try again.')); 
      } 
     } 
     $this->set(compact('employee')); 
     $this->set('_serialize', ['employee']); 
    } 

    public function edit($id = null) 
    { 
     $employee = $this->Employee->get($id, [ 
      'contain' => [] 
     ]); 
     if ($this->request->is(['patch', 'post', 'put'])) { 
      $employee = $this->Employee->patchEntity($employee, $this->request->data); 
      if ($this->Employee->save($employee)) { 
       $this->Flash->success(__('The employee has been saved.')); 

       return $this->redirect(['action' => 'index']); 
      } else { 
       $this->Flash->error(__('The employee could not be saved. Please, try again.')); 
      } 
     } 
     $this->set(compact('employee')); 
     $this->set('_serialize', ['employee']); 
    } 

    public function delete($id = null) 
    { 
     $this->request->allowMethod(['post', 'delete']); 
     $employee = $this->Employee->get($id); 
     if ($this->Employee->delete($employee)) { 
      $this->Flash->success(__('The employee has been deleted.')); 
     } else { 
      $this->Flash->error(__('The employee could not be deleted. Please, try again.')); 
     } 

     return $this->redirect(['action' => 'index']); 
    } 
} 

従業員テンプレート:事前に

<nav class="large-3 medium-4 columns" id="actions-sidebar"> 
    <ul class="side-nav"> 
     <li class="heading"><?= __('Actions') ?></li> 
     <li><?= $this->Html->link(__('New Employee'), ['action' => 'add']) ?></li> 
     <li><?= $this->Html->link(__('Doctors') ?></li> 
     <li><?= $this->Html->link(__('Medical staff') ?></li> 
     <li><?= $this->Html->link(__('Administration') ?></li> 


    </ul> 
</nav> 

<div class="employee form large-9 medium-8 columns content"> 
    <?= $this->Form->create() ?> 
    <fieldset> 
     <legend><?= __('Search Employee') ?></legend> 
     <?= $this->Form->input('Employee_ID',array('type' => 'text', 'label' => 'ID')); ?> 
    </fieldset> 
    <?= $this->Form->button('Search', ['type' => 'submit']); ?> 
    <?= $this->Form->end() ?> 
</div> 


<div class="employee index large-9 medium-8 columns content"> 
    <h3><?= __('Employee') ?></h3> 
    <table cellpadding="0" cellspacing="0"> 
     <thead> 
      <tr> 
       <th scope="col"><?= $this->Paginator->sort('Employee_ID') ?></th> 
       <th scope="col"><?= $this->Paginator->sort('Name') ?></th> 
       <th scope="col"><?= $this->Paginator->sort('Address') ?></th> 
       <th scope="col"><?= $this->Paginator->sort('DOB') ?></th> 
       <th scope="col"><?= $this->Paginator->sort('Contact') ?></th> 
       <th scope="col"><?= $this->Paginator->sort('Gender') ?></th> 
       <th scope="col"><?= $this->Paginator->sort('Salary') ?></th> 
       <th scope="col"><?= $this->Paginator->sort('Category') ?></th> 
       <th scope="col"><?= $this->Paginator->sort('Dept_No') ?></th> 
       <th scope="col" class="actions"><?= __('Actions') ?></th> 
      </tr> 
     </thead> 
     <tbody> 
      <?php foreach ($employee as $employee): ?> 
      <tr> 
       <td><?= h($employee->Employee_ID) ?></td> 
       <td><?= h($employee->Name) ?></td> 
       <td><?= h($employee->Address) ?></td> 
       <td><?= h($employee->DOB) ?></td> 
       <td><?= h($employee->Contact) ?></td> 
       <td><?= h($employee->Gender) ?></td> 
       <td><?= $this->Number->format($employee->Salary) ?></td> 
       <td><?= h($employee->Category) ?></td> 
       <td><?= h($employee->Dept_No) ?></td> 
       <td class="actions"> 
        <?= $this->Html->link(__('View'), ['action' => 'view', $employee->Employee_ID]) ?> 
        <?= $this->Html->link(__('Edit'), ['action' => 'edit', $employee->Employee_ID]) ?> 
        <?= $this->Form->postLink(__('Delete'), ['action' => 'delete', $employee->Employee_ID], ['confirm' => __('Are you sure you want to delete # {0}?', $employee->Employee_ID)]) ?> 
       </td> 
      </tr> 
      <?php endforeach; ?> 
     </tbody> 
    </table> 
    <div class="paginator"> 
     <ul class="pagination"> 
      <?= $this->Paginator->prev('< ' . __('previous')) ?> 
      <?= $this->Paginator->numbers() ?> 
      <?= $this->Paginator->next(__('next') . ' >') ?> 
     </ul> 
     <p><?= $this->Paginator->counter() ?></p> 
    </div> 
</div> 

ありがとう!

答えて

0

インデックス機能でこれを使用してください。if ($this->request->is('get')) { //do something }

関連する問題