CodeIgniter Forums

Full Version: sth confused me
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]vantao[/eluser]
I am a newbie to codeigniter!however, something about CI_URI confused me,let's describe it:
Code:
class CI_URI {

    var    $keyval    = array();
    var $uri_string;
    var $segments        = array();
    var $rsegments        = array();

    /**
     * Constructor
     *
     * Simply globalizes the $RTR object.  The front
     * loads the Router class early on so it's not available
     * normally as other classes are.
     *
     * @access    public
     */
    function CI_URI()
    {
        $this->config =& load_class('Config');
        log_message('debug', "URI Class Initialized");
    }
        }



it's a summary of CI_URI,only include constructor method.
what screwed me is this statement:
Quote:$this->config =& load_class('Config');
as above there has no member $config in class CI_URI,why this statement use it??????

El Forum

[eluser]wiredesignz[/eluser]
Code:
/* line 60 */
    function _fetch_uri_string()
    {
        if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
        ...

Oops

El Forum

[eluser]rogierb[/eluser]
Although it might have been *better* programming to initialize $config, this is now simply done by using the member in the constructor.

So basically one can use any member even if it is not defined;
Using $this->some_member_that_has_not_been_defined = "Some_value"; is allowed.

El Forum

[eluser]vantao[/eluser]
[quote author="wiredesignz" date="1254248765"]
Code:
/* line 60 */
    function _fetch_uri_string()
    {
        if (strtoupper($this->config->item('uri_protocol')) == 'AUTO')
        ...

Oops[/quote]


what do u mean??
detail,please!!!

El Forum

[eluser]wiredesignz[/eluser]
PHP allows variable assignment without definition. RTFM.

El Forum

[eluser]vantao[/eluser]
[quote author="rogierb" date="1254248781"]Although it might have been *better* programming to initialize $config, this is now simply done by using the member in the constructor.

So basically one can use any member even if it is not defined;
Using $this->some_member_that_has_not_been_defined = "Some_value"; is allowed.[/quote]


tks for your explanation!!!
maybe this kind of usage is not friendly to newbie

El Forum

[eluser]wiredesignz[/eluser]
This is a PHP convention, it has nothing to do with CodeIgniter.

El Forum

[eluser]vantao[/eluser]
[quote author="wiredesignz" date="1254249273"]PHP allows variable assignment without definition. RTFM.[/quote]


tks

El Forum

[eluser]BrianDHall[/eluser]
I appreciate your desire to dig into the code and understand it, but for those new (to PHP, MVC, OOP, or just CI) kind of the point of CI is you don't have to dig down in there. I've gone through two commercial projects so far without ever even seeing that bit of code, and I'm still not really any the better for having read and spent the time to understand it Wink

If the magic works, let it Smile

El Forum

[eluser]vantao[/eluser]
[quote author="BrianDHall" date="1254255619"]I appreciate your desire to dig into the code and understand it, but for those new (to PHP, MVC, OOP, or just CI) kind of the point of CI is you don't have to dig down in there. I've gone through two commercial projects so far without ever even seeing that bit of code, and I'm still not really any the better for having read and spent the time to understand it Wink

If the magic works, let it Smile[/quote]


tks , your advice is great