Reputation: 556
i have a problem with HMVC
i have admin controller in all my modules like this
- modules - users - controllers - admin.php - users.php - views - admin_create_user.php - admin_view_users.php - signup.php - login.php - news - controllers - admin.php - news.php - views - admin_disply_news.php - admin_create_news.php - view_news.php
now when go to users admin the URL will be link this
but i need it to be
Upvotes: 0
Views: 1330
Reputation: 117
Add these codes in "core/MY_Router.php" Inside "MY_Router" Class - *(class MY_Router extends MX_Router {** ---code goes in here-- **})*
I tried to do this with routing rules and .htaccess but non of them works. Then I edit the MX_Router code and working perfect but one thing to notice you have to create a sub folder on you'r module's controller call 'admin' and put the controller there to work like this because this way you can use the default routing for modules by calling directly to controller if controller name same as module name.
public $module;
private $located = 0;
protected function _set_request($segments = array()){
$segments = $this->_validate_request($segments);
// If we don't have any segments left - try the default controller;
// WARNING: Directories get shifted out of the segments array!
if (empty($segments))
{
$this->_set_default_controller();
return;
}
if ($this->translate_uri_dashes === TRUE)
{
$segments[0] = str_replace('-', '_', $segments[0]);
if (isset($segments[1]))
{
$segments[1] = str_replace('-', '_', $segments[1]);
}
}
if($segments[0] == 'admin' && isset($segments[1])){
if (isset($segments[2])){
$this->set_method($segments[2]);
$segments[2] = $segments[2];
}else{
$this->set_method('index');
$segments[2] = 'index';
}
$this->directory = '../modules/'.$segments[1].'/controllers/admin/';
$this->module = $segments[1];
$this->class = $segments[1];
$segments[1] = $segments[1];
unset($segments[0]);
$this->uri->rsegments = $segments;
}else{
$segments = $this->locate($segments);
if($this->located == -1)
{
$this->_set_404override_controller();
return;
}
if(empty($segments))
{
$this->_set_default_controller();
return;
}
$this->set_class($segments[0]);
if (isset($segments[1]))
{
$this->set_method($segments[1]);
}
else
{
$segments[1] = 'index';
}
array_unshift($segments, NULL);
unset($segments[0]);
$this->uri->rsegments = $segments;
}
}
Upvotes: 1
Reputation: 8705
You can try to add this to your routes config file:
$route['domain.com/admin/users/(:any)'] = 'domain.com/users/admin/method';
$route['domain.com/admin/news/(:any)'] = 'domain.com/news/admin/method';
When user type domain.com/admin/users/method it will call user controller.
Upvotes: 0