sth confused me

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

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

Oops

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

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

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

#6
[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

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

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


tks

#9
[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

#10
[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


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.