CodeIgniter Forums
sth confused me - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forum-21.html)
+--- Thread: sth confused me (/thread-23066.html)



sth confused me - El Forum - 09-29-2009

[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??????


sth confused me - El Forum - 09-29-2009

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

Oops


sth confused me - El Forum - 09-29-2009

[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.


sth confused me - El Forum - 09-29-2009

[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!!!


sth confused me - El Forum - 09-29-2009

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


sth confused me - El Forum - 09-29-2009

[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


sth confused me - El Forum - 09-29-2009

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


sth confused me - El Forum - 09-29-2009

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


tks


sth confused me - El Forum - 09-29-2009

[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


sth confused me - El Forum - 09-30-2009

[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