Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You're using the <code>Model::read()</code> method method which takes as the second argument the <code>id</code> of the row in your Model's table that you want to access. It's better to use find in this case. You don't need to build a new method in your model or your controller, you can just edit the current <code>view</code> method.</p> <pre><code># in newsses_controller.php: function view($title = null) { $this-&gt;set('title_for_layout', __('News &amp; Event', true)); if (!$id) { $this-&gt;Session-&gt;setFlash(__('Invalid News.', true), 'default', array('class' =&gt; 'error')); $this-&gt;redirect(array('action'=&gt;'index')); } $this-&gt;set('newsse', $this-&gt;Newsse-&gt;find('first', array( 'conditions' =&gt; array('Newsse.title' =&gt; $title) )); $this-&gt;set('newsses', $this-&gt;Newsse-&gt;find('all')); } </code></pre> <p>Or, you can make a more hybrid form in which viewing by id is still possible when a numerical title is given (this assumes you never have news items which have a title consisting of only numeric characters, e.g. '12345').</p> <pre><code># in newsses_controller.php: function view($title = null) { $this-&gt;set('title_for_layout', __('News &amp; Event', true)); if (!$id) { $this-&gt;Session-&gt;setFlash(__('Invalid News.', true), 'default', array('class' =&gt; 'error')); $this-&gt;redirect(array('action'=&gt;'index')); } else if (is_numeric($title)) { $this-&gt;set('newsse', $this-&gt;Newsse-&gt;read(NULL, $title)); } else { $this-&gt;set('newsse', $this-&gt;Newsse-&gt;find('first', array( 'conditions' =&gt; array('Newsse.title' =&gt; $title) )); } $this-&gt;set('newsses', $this-&gt;Newsse-&gt;find('all')); } </code></pre> <p>Finally, you can also replace the <code>find</code> method in my example with a (shorter) custom <code>findBy</code> method (see the <a href="http://book.cakephp.org/view/1026/findBy" rel="nofollow">documentation</a> for more info about this).</p> <pre><code>$this-&gt;Newsse-&gt;findByTitle($title); </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload