Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP MVC Form Processing in which action?
    text
    copied!<p>I am wondering about HTML form processing in MVC. I use Kohana at the moment, but the question is generic in nature. So I want to gather opionions and recommendations about two approaches : </p> <ol> <li><p>Keeping procesing in action, that displays the form:</p> <pre><code>class Controler_Sample { public function action_one { $view = View::factory('form'); if($_POST) { $model = new Model_SomeModel; //validate try($model-&gt;values($_POST)-&gt;save(); { //on success go to action with success logic using post redirect get pattern $this-&gt;request-&gt;redirect('Sample/sucess') } catch(Exception $e) { //on fail attach error message to form view $view-&gt;set('errors',$e-&gt;errors); } } echo $view; } } </code></pre></li> <li><p>Keeping form processing in other action, than this one displaying it</p> <pre><code>class Controler_Sample { public function action_one { //display form, with errors if there are anny passed in GET echo View::factory('form') set-&gt;('errors',$this-&gt;request-&gt;get('errors',FALSE); } public function action_two { if($_POST) { $model = new Model_SomeModel; //validate try($model-&gt;values($_POST)-&gt;save(); { //on success go to action two using post redirect get pattern $this-&gt;request-&gt;redirect('Sample/success') } catch(Exception $e) { //on fail create new hmvc call to action_one with errors in GET //im don't remember the syntax, let's assume it's here ok :D } } } } </code></pre></li> <li><p>Other architecture that you preffer?</p></li> </ol> <p>I see that the first approach is faster to type and process, but the second is more reusable - the action_two, that processes the form could be called from forms or ajax in other places in APP.</p> <p>What do you think ?</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