miladrahimi / phprouter

PhpRouter is a full-featured yet very fast HTTP URL router for PHP projects
MIT License
196 stars 17 forks source link

Any Service Module/View Parameters #6

Closed ranapartap closed 6 years ago

ranapartap commented 7 years ago

Definitely a great router. But lack of few common features like:

Also is there any feature like when we wish to pass any parameter but do not wish to show on url like Wordpress, where can we use www.example.com/hello-world insteadof www.example.com/post/hello-world

Both url has same meaning. but we can omit the "post" parameter.

Also it will be very helpful for new users if you could show any example like how can we use database driven urls like wordpress. Like : hello-world this-is-my-frst-post etc.

Thank you Rana

miladrahimi commented 7 years ago

@ranapartap As for your first three questions, I should say this is a router not template engine, and how-to pass parameters to views is something related to the template engine you want to use. You can use PhpTemplate, another package by me. So you can have something like:

$router->get("/post/{id}", function ($id) {
    $te = TemplateEngineFactory::create();
    $te->setBaseDirectory(__DIR__ . '/views');

    $data = [
        "name"    => "David",
        "surname" => "Gilmour",
        "genres"  => ["Progressive Rock", "Art Rock", "Blues Rock"]
    ];

    return $te->render("singer.html", $data);
});

Furthermore, if creating template engine and setting views directory every time seems painful you can use PhpContainer (a IoC, dependency injection container) which is created by me.

By the way, I'm reviewing my packages and updating them, if you have any idea i will appreciate it if you share it with me.