Simple PHP routing -


I am setting up a simple routing system for my new custom MVC framework, which I am making.

Currently my router sees the cell URL as:

  www.example.com/controller/controller_action/some/other/params  

Therefore, essentially. ..I am reserving the first two sections of the URI for the controller route. However, if I just want to run the following?

  www.example.com/controller/some/other/params  

... which will only try to run the default controller action and additionally Send the parameter?

Here I am using a simple router:

  \ * --- htaccess --- * \ RewriteCond% {REQUEST_FILENAME}! -f rewrite% {REQUEST_FILENAME}! -d RectitRule ^ (. *) $ Index.php? Rt = $ 1 [L, QSA] \ * --- index.php - - * \ if (array_key_exists ('rt', $ _ GET)) {$ path = $ _GET ['rt']; $ Uri = explosion ('/', $ this- & gt; path); If (empty ($ uri [0])) {$ load-> Ctrl ('home'); } Otherwise (below ($ uri [1])) {$ load-> Ctrl ($ uri [0]); } And {$ load-> Ctrl ($ uri [0], $ Yuri [1]); }} And {$ load-> Ctrl ('index'); } \ * --- Loader class --- * \ public function ctrl ($ ctrl, $ action = null) {$ ctrl_name = 'ctrl_' Ucfirst (strtolower ($ ctrl)); $ Ctrl_path = ABS_PATH 'Ctrl /' Strawler ($ ctrl) '.php'; If (file_exists ($ ctrl_path)) {require_once $ ctrl_path;} $ ctrl = new $ ctrl_name (); Is_null ($ verb)? $ Action = "__default": $ action = strtolower ($ verb); $ Ctrl- & gt; $ Action (); }  

How can I do this?

You can handle it This is usually within your controller, when the requested method is not available, Then the MVC framework will call the default method. For example, KohanaPHP has the __ call ($ method, $ parameter) method, to call your desired method and to enter the parameter list as a parameter, just this fallback -Over over the method.

is called when the requested method does not exist. You can handle the logic within its MVC framework or within its functional equivalent.

This allows you to keep the rational internal controller Rather than having it explode between different files.


Comments

Popular posts from this blog

c# - How to capture HTTP packet with SharpPcap -

jquery - SimpleModal Confirm fails to submit form -

php - Multiple Select with Explode: only returns the word "Array" -