S
S
Sergei Makhlenko2014-01-05 19:18:17
CodeIgniter
Sergei Makhlenko, 2014-01-05 19:18:17

How to change/add routers in codeigniter using a hook?

There is a question in changing routers from the codeigniter config.
There are some routing rules in config/routes.php, for example:

$route['default_controller'] = 'pages/page';
$route['404_override'] = '';

$route['manager'] = 'manager';

You need to do the following:
If a certain file exists, then change these routes to
...
$route['(ru|en|fr)/manager'] = 'manager';
...

I suppose that this needs to be done through hooks, but I did not find such a function in the framework to change routes.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Anton Colt, 2014-01-05
@Fix305

Of course, I don’t know the conditions of the task to the end, but what prevents you from checking for the existence of a certain file directly in routes.php? In the same place, depending on the result of the condition, apply the desired $route[]

I
Igor, 2014-01-06
@BugIg

Well, for starters, take a look here.
code-igniter.ru/user_guide/general/hooks.html
Then make the following settings for yourself.

$hook['pre_system'] = array(
                                'class'    => 'MyClass',
                                'function' => 'Myfunction',
                                'filename' => 'Myclass.php',
                                'filepath' => 'hooks',
                                'params'   => array()
                                );

pre_system - will be processed before the routers are loaded, which will give you the opportunity to do whatever you want.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question