title: Check if object exists or is empty in view template
body: <p>How do you check <strong>within the view template</strong> if the result object contains any entries?</p>
  
  <p>(There was a <a href="https://stackoverflow.com/questions/25065005/check-if-record-exists-in-cakephp3">similar question</a> already, but this one is slightly different)</p>
  
  <p>Take the <a href="http://book.cakephp.org/3.0/en/tutorials-and-examples/blog/part-two.html" rel="nofollow noreferrer">CakePHP 3 blog tutorial</a> for example. They show how to list all articles on one page:</p>
  
  <pre><code>// src/Controller/ArticlesController.php
  public function index() {
    $this-&gt;set('articles', $this-&gt;Articles-&gt;find('all'));
  }
  </code></pre>
  
  <p>And the view template:</p>
  
  <pre><code>&lt;!-- File: src/Template/Articles/index.ctp --&gt;
  &lt;table&gt;
    &lt;tr&gt;
      &lt;th&gt;Id&lt;/th&gt;
      &lt;th&gt;Title&lt;/th&gt;
    &lt;/tr&gt;
  &lt;?php foreach ($articles as $article): ?&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;?= $article-&gt;id ?&gt;&lt;/td&gt;
      &lt;td&gt;
        &lt;?= $this-&gt;Html-&gt;link($article-&gt;title, ['action' =&gt; 'view', $article-&gt;id]) ?&gt;
      &lt;/td&gt;
  &lt;/tr&gt;
  &lt;?php endforeach; ?&gt;
  &lt;/table&gt;
  </code></pre>
  
  <p>Disadvantage: <strong>if there are no entries in the database</strong> the HTML table is still rendered.</p>
  
  <p>How can I prevent this and show a simple message like "Sorry no results" insteat?</p>
  
  <p>In <code>CakePHP 2</code> I used</p>
  
  <pre><code>if ( !empty($articles['0']['id']) ) {
    // result table and foreach here
  } else {
    echo '&lt;p&gt;Sorry no results...&lt;/p&gt;';
  }
  </code></pre>
  
  <p>But since <code>$articles</code> is now an object this doesn't work anymore... Is there a new "short way" to check the result object? Or do you usally use another foreach first, like</p>
  
  <pre><code>$there_are_results = false;
  foreach ($articles as $article) {
    if ( !empty($article-&gt;id) ) {
      $there_are_results = true;
      break;
    }
  }
  if ( $there_are_results == true ) {
    // result table and second foreach here
  } else {
    echo '&lt;p&gt;Sorry no results...&lt;/p&gt;';
  }
  </code></pre>
  
  <p>Thanks for your hints.</p>