Welcome Guest, Not a member yet? Register   Sign In
Rewrite url vs Controller
#4

[eluser]osci[/eluser]
You define only route there and then you can remap in your controller
User Guide - Remap

for example
Code:
public function _remap($method, $params = array())
   {
      switch ($method)
      {
         case 'admin':  // Your crud maybe?
         case 'admin_create':
         case 'admin_update':
         case 'admin_delete':
         case 'index': //Your page list maybe, so from admin to index are your reserved words - not to be used in titles
            if (method_exists($this, $method))
            {
               return call_user_func_array(array($this, $method), $params);
            }
            break;
         default:
            $slug = $method;
            $query = $this->your_model->record_exists($slug);
            if ($query)
            {  //this will lead to the desired function, $query->page being from db the function
               return call_user_func_array(array($this, $query->page), $params);
               break;
            }
      }
            
      show_404();
   }


but you should probably make page1, page2, page3 one function ie page since the serve the same purpose (display a title and a content)
and the you would have
Code:
return call_user_func_array(array($this, 'page'), $params);
and manage all the logic from there

btw the title should be translated to safe url (no spaces or disallowed characters), maybe saving it at db while updating record title so you can query against that.


Messages In This Thread
Rewrite url vs Controller - by El Forum - 05-27-2011, 03:36 PM
Rewrite url vs Controller - by El Forum - 05-27-2011, 04:56 PM
Rewrite url vs Controller - by El Forum - 05-28-2011, 07:34 AM
Rewrite url vs Controller - by El Forum - 05-28-2011, 07:39 AM
Rewrite url vs Controller - by El Forum - 05-28-2011, 04:10 PM
Rewrite url vs Controller - by El Forum - 05-29-2011, 02:45 AM



Theme © iAndrew 2016 - Forum software by © MyBB