Hi,
I tried to create my own routing. But It does not work at all. I have my domain: example.local
That should be so:
If I call "example.local/client/namespace" -> namespace = Application\Modules\"namespace"\Controllers\Client
If I call "example.local/namespace" -> namespace = Application\Modules\"namespace"\Controllers
There are also routes for "/client/namespace/controller" and "/namespace/controller" and some more.
But actually if the url is "example.local/client/namespace" phalcon handle the following: -> /namespace/controller instead of /client/namespace
The include order is: ClientRouter first, then PageRouter
Does anybody has a Idea how I can give /client (also /admin) a higer priority if it is in the url?
Here is my code:
class ClientRouter extends Phalcon\Mvc\Router\Group {
protected $config;
public function initialize() {
$this->LoadConfig();
var_dump($_SERVER['REQUEST_URI']);
$this->setHostname($this->config->router->clientHostname);
$this->setPrefix('/client');
$this->add('', $this->GetFallback());
$this->add('/', $this->GetFallback());
//namespace only (eg. gameserver)
$this->add(
':namespace',
[
'namespace' => 1,
'controller' => 'Index',
'action' => 'index',
]
)->convert(
'namespace',
function ($namespace) {
$namespace = 'Application\\Modules\\' . ucfirst($namespace) . '\\Controllers\\Client';
return $namespace;
}
);
//namespace + controller (eg. gameserver/index
$this->add(
':namespace/:controller',
[
'namespace' => 1,
'controller' => 2,
'action' => 'index',
]
)->convert(
'namespace',
function ($namespace) {
$namespace = 'Application\\Modules\\' . ucfirst($namespace) . '\\Controllers\\Client';
return $namespace;
}
);
//namespace + controller + action + params (eg. gameserver/server/edit/34)
$this->add(
':namespace/:controller/:action/:params',
[
'namespace' => 1,
'controller' => 2,
'action' => 3,
'params' => 4,
]
)->convert(
'namespace',
function ($namespace) {
$namespace = 'Application\\Modules\\' . ucfirst($namespace) . '\\Controllers\\Client';
return $namespace;
}
);
unset($this->config);
}
protected function GetFallback() {
return [
'action' => 'index',
'controller' => 'Overview',
'namespace' => 'Application\\Modules\\Index\\Controllers\\Client'
];
}
protected function LoadConfig() {
$this->config = \Application\Core\System::GetInstance()->GetConfig();
}
}
$this->router->mount(new ClientRouter());
class PageRouter extends Phalcon\Mvc\Router\Group {
protected $config;
public function initialize() {
$this->LoadConfig();
$this->setHostname($this->config->router->clientHostname);
$this->setPrefix('/');
//fallback regeln
$this->add('', $this->GetFallback());
$this->add('/', $this->GetFallback());
//namespace only (eg. gameserver)
$this->add(
':namespace',
[
'namespace' => 1,
'controller' => 'Index',
'action' => 'index',
]
)->convert(
'namespace',
function ($namespace) {
$namespace = 'Application\\Modules\\' . ucfirst($namespace) . '\\Controllers\\Page';
return $namespace;
}
);
//namespace + controller (eg. gameserver/index
$this->add(
':namespace/:controller',
[
'namespace' => 1,
'controller' => 2,
'action' => 'index',
]
)->convert(
'namespace',
function ($namespace) {
$namespace = 'Application\\Modules\\' . ucfirst($namespace) . '\\Controllers\\Page';
return $namespace;
}
);
//namespace + controller + action + params (eg. gameserver/server/edit/34)
$this->add(
':namespace/:controller/:action/:params',
[
'namespace' => 1,
'controller' => 2,
'action' => 3,
'params' => 4,
]
)->convert(
'namespace',
function ($namespace) {
$namespace = 'Application\\Modules\\' . ucfirst($namespace) . '\\Controllers\\Page';
return $namespace;
}
);
unset($this->config);
}
protected function GetFallback() {
return [
'action' => 'index',
'controller' => 'Overview',
'namespace' => 'Application\\Modules\\Index\\Controllers\\Page'
];
}
protected function LoadConfig() {
$this->config = \Application\Core\System::GetInstance()->GetConfig();
}
}
$this->router->mount(new PageRouter());