Welcome Guest, Not a member yet? Register   Sign In
newbie question
#1

[eluser]global_erp_solution[/eluser]
I'm a newcomer to codeigniter and somehow I find this one statement very puzzling:

$this->load->view(blah);

that "load" really puzzles me. What is that? I searched everywhere, but no definition is written anywhere, or did I miss it? as a matter of fact, I can't seem to find "view" also. nothing in the CI_Controller class. Thanks
#2

[eluser]LuckyFella73[/eluser]
Have a look at the user guide in general - very helpful.

Regarding your post have a look at this page:
http://ellislab.com/codeigniter/user-gui...oader.html
#3

[eluser]global_erp_solution[/eluser]
thanks for the quick reply. I've read the link before, but still unable to understand the true nature of "load". is it a variable? if so, I don't see it declared anywhere. not in CI_Controller nor in Loader class. the closest I can guess is it's an instance of Loader class, therefore it can invoke view() method in Loader class. but then that means CI_Controller must have a reference of an instance of Loader class, which I couldn't find. can you explain this? thanks
#4

[eluser]LuckyFella73[/eluser]
Look at core/Controller.php line 49 ( CI 2.0.2 ) and core/Common.php
#5

[eluser]InsiteFX[/eluser]
See the ./system/core/Loader.php file.
#6

[eluser]global_erp_solution[/eluser]
sorry guys, still not getting it. In my mind, I'm expecting a declaration like
Code:
public $load;

and couldn't find that declaration in Loader, Controller or Common. My background is java, so i my mind the code above is the way to declare instance variable. or do you guys do instance variable declaration differently in PHP? thanks
#7

[eluser]LuckyFella73[/eluser]
In Controller.php you have
Code:
$this->load =& load_class('Loader', 'core');

Where "load_class" is a function declared in Common.php
Was it that what you meant?
#8

[eluser]InsiteFX[/eluser]
See as LuckyFella73 showed you ./system/core/Controller.php
Code:
// See how it is assigning the Loader Class instance to $this->load
$this->load =& load_class('Loader', 'core');

Now view ./system/core/Loader.php and all of it's methods/functions
#9

[eluser]global_erp_solution[/eluser]
yes, I saw that assignment part. I understood that part.
In my understanding (at least in java, .Net, C++, VB and any other language I've used), before assigning to a variable, you need to declare it first. Do you mean we can declare and assign at the same time in PHP?
I was hoping for something like this:
Code:
//first the declaration
public $load;

//and then the assignment
$this->load= getLoader();

while in Controller, I only see the assignment part. the declaration part is nowhere to be found. So, no need for declaration in PHP? just assign something and it's declared automatically? thans
#10

[eluser]LuckyFella73[/eluser]
You don't have to (must) declare class variables / properties.
But usually it's bad coding style - I don't know the reason
"$this->load" isn't declared - I guess there is a reason
(better ask oop pros).

Bear in mind that all class properties that are not declared
are public automatically!

See this page:
http://php.net/manual/en/language.oop5.properties.php




Theme © iAndrew 2016 - Forum software by © MyBB