Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

handle 404 request #101

Open
awlad opened this issue Nov 9, 2015 · 2 comments
Open

handle 404 request #101

awlad opened this issue Nov 9, 2015 · 2 comments

Comments

@awlad
Copy link

awlad commented Nov 9, 2015

Hi,
I am new to use this awesome library. I am having bit trouble to find an example of http 404 request. How do I handle 404 requests?

@c9s
Copy link
Owner

c9s commented Nov 9, 2015

You simply check if there is any returned route. If nothing is returned,
its 404 not found

awlad [email protected] 於 2015年11月10日 星期二寫道:

Hi,
I am new to use this awesome library. I am having bit trouble to find an
example of http 404 request. How do I handle 404 requests?


Reply to this email directly or view it on GitHub
#101.

@awlad
Copy link
Author

awlad commented Nov 9, 2015

If any above route not match then i want to render a view for 404 with a controller.

use Pux\RouteExecutor;
$mux = new Pux\Mux;

class ProductController {
public function listAction() {
return 'product list';
}
public function itemAction($id) {
return "product $id";
}
}
$mux = new Pux\Mux;
//var_dump($mux);
$mux->any('/product', ['Module\controllers\EmployeesController','index']);
$mux->get('/product/:id', ['ProductController','itemAction'] , [
'require' => [ 'id' => '\d+', ],
'default' => [ 'id' => '1', ]
]);
// not match above pattern so 404
$mux->any('.*', ['Module\controllers\WelcomeController','not_found']);

$route = $mux->dispatch($_SERVER['REQUEST_URI']);

I want to rebder welcome#not_found. how can i do that?

echo RouteExecutor::execute($route);

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants