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
Reply
#3

(04-22-2024, 07:01 AM)sjender Wrote: 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?

You can't. Because we can have only one global function.
If you don't need to change the behavior of the uri_to(), I recommend you add a new function like my_url_to().
Reply




Theme © iAndrew 2016 - Forum software by © MyBB