Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Have a look at the <a href="http://martinfowler.com/eaaCatalog/transactionScript.html" rel="nofollow noreferrer">Transaction Script</a> and <a href="http://martinfowler.com/eaaCatalog/pageController.html" rel="nofollow noreferrer">PageController</a> patterns. Transaction script is the most basic of the Domain Logic patterns and suited for small applications. A PageController's purpose is to handle input from your UI. If you want that to be a single command, that's okay. You could do</p> <pre><code>class PostAddController implements RequestHandler { public function handle($request) { $post = filter_input(INPUT_POST, 'post', FILTER_SANITIZE_SPECIAL_CHARS); $model = new PostAddTransactionScript; $model-&gt;process($post); include 'postAddViewScript.php'; } } </code></pre> <p>PostAddTransactionScript would then write the $postData to the database or whatever it is supposed to do. The simplified example above would still be in accordance to MVC because it keeps the Model logic inside the transaction script and the input handling inside the presentation layer.</p> <p>Whether you organize your input handling logic into a single Controller class or many smaller commands is up to you. Grouping responsibilities just makes more sense, especially if you need to share state or common functionality between the Commands.</p> <p>As for your example, I'd rather use the <a href="http://sourcemaking.com/design_patterns/strategy" rel="nofollow noreferrer">Strategy Pattern</a> and have the Post_Parent use a Command instead of the command using the Parent, e.g.</p> <pre><code>$commander = new PostCommander; $commander-&gt;setStrategy(new PostAddCommand); $commander-&gt;handle($_POST); </code></pre> <p>In any case, I agree with the others that your controllers should be thin and the model should do the main work.</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