Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I think you're somewhat on the right track with the latter approach. However, you should not hard code the calling of actions in your bootstrap. The bootstrap should interpret the URL and call the action methods dynamically through the use of a function like <code>call_user_func_array</code>.</p> <p>Also, I would suggest that you leave the rendering of views up to the action code so the action logic is self sufficient and flexible. That would allow the action to analyse the input for correctness and render errors or views appropriately. Also, you've got the method 'deleteItem' on your controller, but that should really be the work of a model. Perhaps you should read up some more on MVC and try to work with an existing framework to understand the concepts better before you try to implement your own framework (I would suggest the Yii framework for that).</p> <p>Here's an example of how <strong>I think</strong> your logic should be implemented in a good MVC framework.</p> <pre><code>class ListController extends BaseController { public function CreateAction($title){ if(ctype_alnum($title)) { $list = new List(); $list-&gt;Title = $title; if($list-&gt;insert()) { $this-&gt;render_view('list/create_successful'); } else { $this-&gt;render_view('list/create_failed'); } } else { $this-&gt;render_view('list/invalid_title'); } } public function DeleteAction($id){ $list = List::model()-&gt;getById($id); if($list == null) { $this-&gt;render_view('list/errors/list_not_found'); } elseif($list-&gt;delete()) { $this-&gt;render_view('list/delete_successful'); } else { $this-&gt;render_view('list/delete_failed'); } } } </code></pre> <p><a href="http://anantgarg.com/2009/03/13/write-your-own-php-mvc-framework-part-1/" rel="nofollow">here is a great tutorial on how to write your own MVC framework</a></p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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