08.22 php saved
rafaelbandeira3
Tags add more
data  
Note
That's the result of the implementations, I'm not exposing the implementation itself because I'm looking forward for nice subjects for posting and code releases... spread the word and knowledge, and stuff :) ... lets say I'm really excited about having made a boom in my carrer by introducing cakephp in my company - and for having invested uncountable hours reading, testing and debugging cakephp stuffs!
  1. // controller actions
  2.     function schedules()
  3.     {
  4.         $this->Employee->contain('Schedule');
  5.         $data = $this->Employee->findById($this->AppAuth->User->id);
  6.         $this->set(compact('data'));
  7.         return $data;
  8.     }
  9.  
  10. // with more than one var setted
  11. function timesheet()
  12. {
  13.     [...]
  14.  
  15.         if(!empty($data))
  16.         {
  17.             $totalWorkedTime = $this->Employee->WorkTime->find('totalWorkedTime', array (
  18.                 'conditions' => array ( $this->Employee->WorkTime->primaryKey => Set::extract (
  19.                         '{}.' . $this->Employee->WorkTime->alias . '.' . $this->Employee->WorkTime->primaryKey
  20.                         ,$data
  21.                 ))
  22.             ));
  23.         }
  24.  
  25.         $from = $passedParams['from'];
  26.         $to = $passedParams['to'];
  27.  
  28.         $this->set(compact('data', 'totalWorkedTime', 'from', 'to'));
  29.         return $data;
  30. }
  31.  
  32.  
  33.  
  34. // var $data raw usage
  35. // example 1 ... wich is a little bit more readable, but I don't like it... actually i prohibited them to do that :)
  36.     <ul class="List">
  37.     <?php foreach($data as $entry): extract($entry); $count++; ?>
  38.         <li class="Entry <?php echo $count%2?'odd':'even' ?>">
  39.             <dl class="Primary Field DisplayField">
  40.                 <dt class="Name">
  41.                     Empresa
  42.                 </dt>
  43.                 <dd class="Value">
  44.                     <?php echo $html->link($Company['trade_name'],
  45. array('controller' => 'crud',
  46. 'model' => 'company',
  47. 'action' => 'edit',               $Company['id'])) ?>
  48.                 </dd>
  49.             </dl>
  50.             <dl class="Association Field DisplayField">
  51.                 <dt class="Name">
  52.                     Contato
  53.                 </dt>
  54.  
  55. // example 2
  56. <?php if(empty($data)): ?>
  57.     <?php echo $localize->message($this->params['action'] . '.noData') ?>
  58. <?php else: ?>
  59.     <ul class="List">
  60.         <?php foreach($data  as $entry): ?>
  61.         <li class="Entry">
  62.             <dl class="Field DisplayField">
  63.                 <dt class="Name">
  64.                     Nome
  65.                 </dt>
  66.                 <dd class="Value">
  67.                     <?php echo $entry['Company']['trade_name'] ?>
  68.                 </dd>
  69.             </dl>
  70.  
  71. ////////////////////////////////////////////
  72. // Helper Example
  73.  
  74.     function beforeRender()
  75.     {
  76.         $View =& ClassRegistry::getObject('View');
  77.  
  78.         if(!empty($View->viewVars['data']))
  79.         {
  80.             $this->data = $View->viewVars['data'];
  81.             if(!isset($this->data[0]))
  82.                 $this->data = array($this->data);
  83.         }
  84.        
  85.         return true;
  86.     }
  87.  
  88.  
  89. // With the helper, in the view
  90.     <thead>
  91.         <tr>
  92.             <?php
  93.             echo $view->fieldName('EmployeeWorktime.client_id');
  94.             echo $view->fieldName('EmployeeWorktime.check_in');
  95.             echo $view->fieldName('EmployeeWorktime.check_out');
  96.             echo $view->fieldName('EmployeeWorktime.worked_time');
  97.             ?>
  98.         </tr>
  99.     </thead>
  100.     <tbody>
  101.         <?php while($view->next()): ?>
  102.         <tr class="Entry">
  103.             <?php
  104.             echo $view->fieldValue('Client.trade_name',
  105.                                   array('link' => array('title' => 'See only from company : %s')));
  106.        
  107.             echo $view->fieldValue('EmployeeWorkTime.check_in');
  108.             echo $view->fieldValue('EmployeeWorkTime.check_out');
  109.             echo $view->fieldValue('EmployeeWorkTime.worked_time');
  110.             ?>
  111.         </tr>
  112.         <?php endwhile ?>
  113.     </tbody>
Parsed in 0.216 seconds, using GeSHi 1.0.7.14

Modify this Paste