cakephp, link to retrieve status variable -


total n00b in cakephp

im trying link view retrieved data variable $status, defined in controller, given simple condition "done" or "pending".

given model:

<?php     class task extends appmodel {     var $name = 'task';     var $validate = array(     'title' => array(     'rule' => 'notempty',     'message' => 'title of task cannot empty'     )     ); }?> 

the task controller:

        function index($status=null) {         if($status == 'done')         $tasks = $this->task->find('all', array('conditions' => array('task.done' => '1')));         else if($status == 'pending')         $tasks = $this->task->find('all', array('conditions' => array('task.done' => '0')));         else          $tasks = $this->set('tasks', $this->task->find('all'));          $this->set('tasks', $tasks);         $this->set('status', $status);         } 

and view:

<h2>tasks</h2>  <?php if(empty($tasks)): ?>              there no tasks in list <?php else: ?>     <table>         <tr>             <th>title</th>             <th>status</th>             <th>created</th>             <th>modified</th>             <th>actions</th>         </tr>         <?php foreach ($tasks $task): ?>         <tr>             <td>                 <?php echo $task['task']['title'] ?>             </td>                    <td>                 <?php                 if($task['task']['done']) echo "done";                 else echo "pending";                 ?>             </td>             <td>                 <?php echo $task['task']['created'] ?>             </td>             <td>                 <?php echo $task['task']['modified'] ?>             </td>             <td>                 <?php echo $this->html->link('edit', array('action'=>'edit', $task['task']['id'])); ?>                 <?php echo $this->html->link('delete', array('action'=>'delete', $task['task']['id']), null, 'are sure want delete task?'); ?>              </td>         </tr>         <?php endforeach; ?>     </table>     <?php endif; ?>      <?php echo $this->html->link('list done tasks', array('action'=>'index','done')); ?><br />     <?php echo $this->html->link('list pending tasks', array('action'=>'index', 'pending')); ?><br />  

clicking "done task" returns empty list (there no tasks in list). can see wrong on link? in advance!

as mentioned mcwayweb above case of variable incorrect.

as setting lower case vars use in view make change there. change counts of task in view task.

i consider setting viewvars @ same time using below

$this->set(compact('tasks','status)); 

Comments

Popular posts from this blog

Email notification in google apps script -

c++ - Difference between pre and post decrement in recursive function argument -

javascript - IE11 incompatibility with jQuery's 'readonly'? -