Welcome Guest, Not a member yet? Register   Sign In
Extend config class does not work
#1

I want to add a static_url and make_url method in Config class and url_helper helper, so that I can make url in the view pages.
PHP Code:
class MY_Config extends CI_Config {

    public function 
__construct()
    {
        
parent::__construct();
    }

    public function 
static_url($uri ''$protocol NULL)
    {
        
$static_url $this->slash_item('static_url');

        if (isset(
$protocol))
        {
            
$static_url $protocol.substr($static_urlstrpos($static_url'://'));
        }

        return 
$static_url.ltrim($this->_uri_string($uri), '/');
    }

    public function 
make_url($name$uri ''$protocol NULL)
    {
        
$make_url $this->slash_item($name);

        if (isset(
$protocol))
        {
            
$make_url $protocol.substr($make_urlstrpos($make_url'://'));
        }

        return 
$make_url.ltrim($this->_uri_string($uri), '/');
    }

PHP Code:
if ( ! function_exists('static_url'))
{
    function 
static_url($uri ''$protocol NULL)
    {
        return 
get_instance()->config->static_url($uri$protocol);
    }
}

if ( ! 
function_exists('make_url'))
{
    function 
make_url($name$uri ''$protocol NULL)
    {
        return 
get_instance()->config->make_url($name$uri$protocol);
    }


But when test this, error occurs:

A PHP Error was encountered

Severity: Error

Message: Call to undefined method CI_Config:Confusedtatic_url()

Filename: helpers/MY_url_helper.php

Line Number: 8

Backtrace:

-------------------

why the static_url cannot find the new method in extended Config class ??
Reply
#2

You're asking the wrong question ...

The error message shows that it is looking for a CI_Config method, as opposed to a MY_Config one. You should be looking into why your MY_Config class isn't loaded. My guess is you haven't named the file properly - it has to be 'MY_Config.php', case-sensitive.
Reply
#3

Also where did you place your new extended files?
Reply
#4

(05-05-2015, 08:34 AM)CroNiX Wrote: Also where did you place your new extended files?

Yes, it is .

I placed MY_Config.php in application\libraries, but it should be in application\core.

resolved!
Reply




Theme © iAndrew 2016 - Forum software by © MyBB