Welcome Guest, Not a member yet? Register   Sign In
extend url_to helper
#1

Hi,
I would like to extend the url_to() helper function.
This is what I did...
PHP Code:
<?php

use CodeIgniter\Router\Exceptions\RouterException;

function 
url_to(string $controller, ...$args): string
{
    if(empty($_GET['ref'])){
        return original_url_to($controller, ...$args);
    }

    /* EXTRA CODE */
}

//This is a copy of the original CI4 url_to function
function original_url_to(string $controller, ...$args): string
{
    if(!$route route_to($controller, ...$args)){
        $explode explode('::'$controller);

        if(isset($explode[1])){
            throw RouterException::forControllerNotFound($explode[0], $explode[1]);
        }

        throw RouterException::forInvalidRoute($controller);
    }

    return site_url($route);


But I would prefer I didn't have to make a copy of the original function, but refer directly to the CI4 function instead,
How can do this?
Reply


Messages In This Thread
extend url_to helper - by sjender - 04-22-2024, 07:01 AM
RE: extend url_to helper - by datamweb - 04-22-2024, 01:58 PM
RE: extend url_to helper - by kenjis - 04-22-2024, 02:33 PM



Theme © iAndrew 2016 - Forum software by © MyBB