Welcome Guest, Not a member yet? Register   Sign In
Override Router
#1

Hi folks!

I'm trying to override the router.

From what I can make out, the best way to do this is to edit the service first.

So, in my app/Services.php, I have the following:-

PHP Code:
<?php

namespace Config;

use 
CodeIgniter\Config\BaseService;

class 
Services extends BaseService
{
 
    public static function router(RouteCollectionInterface $routes nullRequest $request nullbool $getShared true)
    {
        if ($getShared) {
            return static::getSharedInstance('router'$routes$request);
        }

        $routes $routes ?? static::routes();
        $request $request ?? static::request();

        return new Router($routes$request);
    }


The function is copied directly from the system services file. So, in theory, as it's unchanged, it should work as usual?

However, I now get the following error:- 

Argument 1 passed to Config\Services::router() must be an instance of Config\RouteCollectionInterface or null, instance of CodeIgniter\Router\RouteCollection given, called in /var/www/vhosts/creative-spectrum.co.uk/public_html/micronet/system/CodeIgniter.php on line 807
Reply




Theme © iAndrew 2016 - Forum software by © MyBB