Note that there are some explanatory texts on larger screens.

plurals
  1. POAm I "doing it wrong" in Kohana 3?
    text
    copied!<p>When I have a controller, e.g. article I often have a <code>action_view()</code> that handles most of the code.</p> <p>Sometimes, it can become 80-100 lines long.</p> <p>My controller usually handles all of these:</p> <ul> <li>binding template variables</li> <li>setting sessions (where appropriate)</li> <li>sending emails</li> <li>validating forms</li> </ul> <p>I could see bit and pieces that I could make another private method in the controller, not necessarily for reuse, but for separation of concerns. </p> <p>However, then it looks weird (to me) having methods which can be called via a route, and methods that are internal only.</p> <p>Also some things say to me "I should be in the model, not the controller". However, I'm not sure if that's correct either.</p> <p>In the end, I have a somewhat fat controller method that looks quite procedural.</p> <p>Should I actually have a list up top of my <code>action_*</code> methods, and then separate the rest of my code into smaller modules?</p> <p>I've got an example below... is this typical controller stuff, or should the sessions etc be in the model?</p> <pre><code>public function action_pdf($type, $id) { // Get PDF file from db and send headers to it $id = (int) $id; $pdfFile = $this-&gt;model-&gt;getPdf($id, $type); if ($pdfFile) { $this-&gt;request-&gt;redirect($pdfFile); } else { $this-&gt;session-&gt;set('pdfMissing', true); $this-&gt;request-&gt;redirect(Route::get('properties')-&gt;uri()); } } </code></pre> <p>So, my question is, am I doing it wrong?</p>
 

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