return 404 on non existing controller/action and refactor index.php
This commit is contained in:
parent
1388fc1205
commit
1f27156004
@ -55,11 +55,11 @@ final class controller
|
||||
public function execute()
|
||||
{
|
||||
if (!class_exists($this->_A_urlParts['controller'])) {
|
||||
throw new ControllerException("Controller " . $this->_A_urlParts['controller'] . " is not valid.");
|
||||
throw new NotFoundException("Controller " . $this->_A_urlParts['controller'] . " is not valid.");
|
||||
}
|
||||
|
||||
if (!method_exists($this->_A_urlParts['controller'], $this->_A_urlParts['action'])) {
|
||||
throw new ControllerException("Action " . $this->_A_urlParts['action'] . " of controller " .
|
||||
throw new NotFoundException("Action " . $this->_A_urlParts['action'] . " of controller " .
|
||||
$this->_A_urlParts['controller'] . " is not valid.");
|
||||
}
|
||||
|
||||
|
3
Kernel/Exceptions/NotFoundException.php
Normal file
3
Kernel/Exceptions/NotFoundException.php
Normal file
@ -0,0 +1,3 @@
|
||||
<?php
|
||||
|
||||
class NotFoundException extends Exception {}
|
17
index.php
17
index.php
@ -16,6 +16,8 @@
|
||||
|
||||
View::openBuffer();
|
||||
|
||||
$ret = Utils::RETURN_HTML;
|
||||
|
||||
try
|
||||
{
|
||||
$O_controller = new Controller($S_url, $A_postParams, $A_getParams);
|
||||
@ -23,19 +25,18 @@
|
||||
}
|
||||
catch (ControleurException $O_exception)
|
||||
{
|
||||
echo ('An error occured: ' . $O_exception->getMessage());
|
||||
View::openBuffer();
|
||||
View::show("errors/500", $O_exception->getMessage());
|
||||
}
|
||||
catch (NotFoundException $O_exception)
|
||||
{
|
||||
View::openBuffer();
|
||||
View::show("errors/404");
|
||||
}
|
||||
catch (HTTPSpecialCaseException $O_exception)
|
||||
{
|
||||
// drop old buffer
|
||||
View::closeBuffer();
|
||||
View::openBuffer();
|
||||
|
||||
View::show("errors/".$O_exception->getHTTPCode(), $O_exception->getMsg());
|
||||
|
||||
$content = View::closeBuffer();
|
||||
View::show('html', array('body' => $content));
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user