title: migrating cakephp 2.5 code to use cakephp 3.0 objects
body: <p>I migrating a 2.5 app to cakePHP 3.0 and I am updating my code to use the ORM objects after <code>find()</code> rather than the arrays.</p>
  
  <p>In my 2.5 view I do an array find and count the results. But I cannot seem to access the object level I need to do the count in the new code.</p>
  
  <p>2.5 Code:</p>
  
  <pre><code>&lt;?php foreach ($recentEmployees as $recentEmployee): ?&gt;
      &lt;tr&gt;
          &lt;td&gt;
              &lt;?php echo ($recentEmployee['Employee']['name']); ?&gt;
          &lt;/td&gt;
          &lt;td&gt;&lt;?php echo h($this-&gt;Time-&gt;format('d/m/Y', $recentEmployee['Employee']['created'])); ?&gt;&lt;/td&gt;
          &lt;td&gt;
              &lt;?php
                  $completedCourses = count(
                                          array_filter(           
                                              $recentEmployee['Course'], 
                                              function($item){return $item['CoursesEmployee']['completed'];}  
                                                      )
                                          );
                  $totalCourse = count($recentEmployee['Course']);      
              ?&gt;
              &lt;span class="label &lt;?php echo($label); ?&gt;"&gt;
              &lt;?php 
                  echo ($completedCourses); 
              ?&gt;      
              /&lt;?php echo ($totalCourse); ?&gt;
          &lt;/td&gt;
      &lt;/tr&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <p>Now my 3.0 code and the object I am trying access and count:</p>
  
  <pre><code>&lt;?php foreach ($recentEmployees as $recentEmployee): ?&gt;
      &lt;tr&gt;
          &lt;td&gt;&lt;?= h($recentEmployee-&gt;name) ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?= h($this-&gt;Time-&gt;format($recentEmployee-&gt;created, 'd/M/Y')) ?&gt;&lt;/td&gt;
          &lt;td&gt;&lt;?= debug($recentEmployee-&gt;courses) ?&gt;&lt;/td&gt;
      &lt;/tr&gt;
  &lt;?php endforeach; ?&gt;
  </code></pre>
  
  <p>Object:</p>
  
  <pre><code>[
  (int) 0 =&gt; object(App\Model\Entity\Course) {
  
      'id' =&gt; (int) 1,
      'name' =&gt; 'Manual Handling Training',
      'course_lenght' =&gt; object(Cake\I18n\Time) {
  
          'time' =&gt; '2015-05-28T02:12:00+0000',
          'timezone' =&gt; 'UTC',
          'fixedNowTime' =&gt; false
  
      },
      '_joinData' =&gt; object(App\Model\Entity\CoursesEmployee) {
  
          'course_id' =&gt; (int) 1,
          'id' =&gt; (int) 1,
          'employee_id' =&gt; (int) 1,
          'course_module_id' =&gt; (int) 5,
          'progress' =&gt; (int) 10,
          'modified' =&gt; object(Cake\I18n\Time) {
  
              'time' =&gt; '2014-12-16T22:40:42+0000',
              'timezone' =&gt; 'UTC',
              'fixedNowTime' =&gt; false
  
          },
          'created' =&gt; object(Cake\I18n\Time) {
  
              'time' =&gt; '2014-11-18T00:00:00+0000',
              'timezone' =&gt; 'UTC',
              'fixedNowTime' =&gt; false
  
          },
          'completed' =&gt; false,
          '[new]' =&gt; false,
          '[accessible]' =&gt; [
              'employee_id' =&gt; true,
              'course_id' =&gt; true,
              'course_module_id' =&gt; true,
              'progress' =&gt; true,
              'completed' =&gt; true,
              'employee' =&gt; true,
              'course' =&gt; true,
              'course_module' =&gt; true
          ],
          '[dirty]' =&gt; [],
          '[original]' =&gt; [],
          '[virtual]' =&gt; [],
          '[errors]' =&gt; [],
          '[repository]' =&gt; 'CoursesEmployees'
  
      },
      '[new]' =&gt; false,
      '[accessible]' =&gt; [
          'name' =&gt; true,
          'course_lenght' =&gt; true,
          'course_files' =&gt; true,
          'course_modules' =&gt; true,
          'employees' =&gt; true
      ],
      '[dirty]' =&gt; [],
      '[original]' =&gt; [],
      '[virtual]' =&gt; [],
      '[errors]' =&gt; [],
      '[repository]' =&gt; 'Courses'
  
  },
  (int) 1 =&gt; object(App\Model\Entity\Course) {
  
      'id' =&gt; (int) 3,
      'name' =&gt; 'Treacys Hotel Induction Training',
      'course_lenght' =&gt; object(Cake\I18n\Time) {
  
          'time' =&gt; '2015-05-28T01:25:00+0000',
          'timezone' =&gt; 'UTC',
          'fixedNowTime' =&gt; false
  
      },
      '_joinData' =&gt; object(App\Model\Entity\CoursesEmployee) {
  
          'course_id' =&gt; (int) 3,
          'id' =&gt; (int) 2,
          'employee_id' =&gt; (int) 1,
          'course_module_id' =&gt; (int) 8,
          'progress' =&gt; (int) 100,
          'modified' =&gt; object(Cake\I18n\Time) {
  
              'time' =&gt; '2014-12-08T00:07:18+0000',
              'timezone' =&gt; 'UTC',
              'fixedNowTime' =&gt; false
  
          },
          'created' =&gt; object(Cake\I18n\Time) {
  
              'time' =&gt; '2014-11-20T00:00:00+0000',
              'timezone' =&gt; 'UTC',
              'fixedNowTime' =&gt; false
  
          },
          'completed' =&gt; true,
          '[new]' =&gt; false,
          '[accessible]' =&gt; [
              'employee_id' =&gt; true,
              'course_id' =&gt; true,
              'course_module_id' =&gt; true,
              'progress' =&gt; true,
              'completed' =&gt; true,
              'employee' =&gt; true,
              'course' =&gt; true,
              'course_module' =&gt; true
          ],
          '[dirty]' =&gt; [],
          '[original]' =&gt; [],
          '[virtual]' =&gt; [],
          '[errors]' =&gt; [],
          '[repository]' =&gt; 'CoursesEmployees'
  
      },
      '[new]' =&gt; false,
      '[accessible]' =&gt; [
          'name' =&gt; true,
          'course_lenght' =&gt; true,
          'course_files' =&gt; true,
          'course_modules' =&gt; true,
          'employees' =&gt; true
      ],
      '[dirty]' =&gt; [],
      '[original]' =&gt; [],
      '[virtual]' =&gt; [],
      '[errors]' =&gt; [],
      '[repository]' =&gt; 'Courses'
  
  },
  ]
  </code></pre>
  
  <p>I have tried this but it is a bad mess of objects and arrays</p>
  
  <pre><code>$completedCourses = count(
                          array_filter(
                              $recentEmployee-&gt;courses, 
                              function($item){return $item['CoursesEmployee']['completed'];}  
                                      )
                              );
  </code></pre>
  
  <p>****UPDATE</p>
  
  <p>I have accessed the data by pointing in _jointable. This is surely not the best practice?</p>
  
  <pre><code> &lt;?= $completedCourses = count(
                              array_filter(
                                  $recentEmployee-&gt;courses,
                                  function($item){return $item['_joinData']['completed'];}
                                          )
                              );?&gt;
  </code></pre>