Routing parameters in frameworks
Posted: Sun Jan 30, 2011 5:04 am
In which way CodeIgniter, cakePHP or Zend Framework are routing HTTP requests.
Is it like this:
This is the way frameworks control methods as subpages, but how 'bout parameters. It is easy when method in controller has only one parameter.
Example:
Then URL will be:
But what if method has two, three or four parameters, how to automaticly generate path seperators with parameters through .htaccess?
In $_GET, that would be like this:
But what if there are more parameters, that should be:
or (without .htaccess)
This is the way CodeIgniter controls routes, but I can't find specific code for generating .htaccess, or $_GET.
I hope you understand what I mean, so please help
Is it like this:
Code: Select all
Blog index:
http://localhost/Blog/ or http://localhost/Blog/index
New post:
http://localhost/Blog/new_postCode: Select all
class Blog // implements Controller; extends Controller
{
public function index()
{
$this->get_view('blog_index');
}
public function new_post()
{
$this->get_view('blog_new_post');
}
}Example:
Code: Select all
public function get_post($id = null)
{
if (!is_null($id))
{
// querying post
}
}Code: Select all
Getting searched post:
http://localhost/Blog/get_post/id (http://localhost/Blog/get_post/1)In $_GET, that would be like this:
Code: Select all
http://localhost/index.php?controller=Blog&method=get_post¶meter1=idCode: Select all
http://localhost/Blog/get_post/id/name/something_elseCode: Select all
http://localhost/index.php?controller=Blog&method=get_post¶meter1=id¶meter2=name¶meter3=something_elseI hope you understand what I mean, so please help