Hi guys!
how to call Route of the database, if it is not in the list of standard routing. This code works, but it does not work for some reason /users/{id} (return 404)
Routes.php:
$router = new Phalcon\Mvc\Router(false);
$router->removeExtraSlashes(true);
$router->notFound(array(
'controller' => 'Page',
'action' => '_404'
));
/**
* See it! ↓
*/
$router->add('{url:[a-zA-Z0-9\.\/]+}', array(
'controller' => 'url',
'action' => 'distrib',
));
$router->add('/', array(
'controller' => 'index',
'action' => 'index',
));
$router->add('/login', array(
'controller' => 'Auth',
'action' => 'login',
));
$router->add('/user/{id:[0-9]+}', array(
'controller' => 'Users',
'action' => 'profile',
));
$router->add('/biz/{alias:[a-z0-9-]+}', array(
'controller' => 'Biz',
'action' => 'show',
));
UrlController(distribAction):
public function distribAction() {
$url = $this->dispatcher->getParam('url');
$urlFound = Urls::findFirstByUrl($url);
// Если URL найден
// If URL found
if($urlFound) {
// Если это старый урл, делаем 301 на новый
// If it a old url, make 301 to new
if($urlFound->as301) {
$this->view->disable();
$this->response->redirect($urlFound->as301, true, 301)->send();
}
// Или передаем управление указанному контроллеру
// Or forward to selected controller
else {
$this->dispatcher->forward([
'controller' => $urlFound->controller,
'action' => $urlFound->action,
'params' => $urlFound->params,
]);
}
}
// Если URL не найден, отдаем 404
// If URL not found - forward to 404-Page
else {
$this->dispatcher->forward([
'controller' => 'Page',
'action' => '_404',
]);
}
}
Database table url: