I want a 'global link' to each module like this:
Inside application/config/routes.php
$route['search'] = 'searchPage';
if the user is typing search in the url it needs to go to module searchPage, there is where the routes inside the module comes in. Or that's my plan, I want a default routing inside that module.
Inside modules/searchPage/config/routes.php
$route['searchPage'] = 'Welcome/showMessage';
go to the Welcome controller with function showMessage.
-modules
--searchPage
---config
----routes.php
---controllers
---views
---models
inside my Welcome controller:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Welcome extends MX_Controller {
public function showMessage()
{
$this->load->view('test');
}
}
?>
Version: Wiredesignz 5.5 and codeigniter 3.0.3
But this don't work. Can someone explain why this doesn't work?
I found a solution:
I have placed this code in application/config/routes.php
$modules_path = APPPATH.'modules/';
$modules = scandir($modules_path);
foreach($modules as $module)
{
if($module === '.' || $module === '..') continue;
if(is_dir($modules_path) . '/' . $module)
{
$routes_path = $modules_path . $module . '/config/routes.php';
if(file_exists($routes_path))
{
require($routes_path);
}
else
{
continue;
}
}
}
And inside modules/searchPage/config/routes.php
$route['searchPage'] = 'searchPage/Welcome/showMessage';
Your structure is not well performed
-modules
--searchPage
---config
----routes.php
---controllers
---views
---models
it should look like this
-config
--routes.php
-modules
--searchPage
---controllers
---views
---models
you can only have one config folder and has to be outside the modules folder, same as all the php files of configuration
If your module is named searchPage
$route['searchPage'] = 'searchPage/welcome/showMessage';
$route['some_name'] = 'module/controller/function';
Directory Example
modules >
modules > searchPage >
modules > searchPage > controllers >
modules > searchPage > controllers > Welcome.php
If you did not remove index.php with a htaccess you may need to include index.php in you url.
With your config and routes in your modules folder it is best to use the one in the main application > config > routes.php
and application > config > config.php
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.