CodeIgniter Forums
$this->load->view() ??? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Libraries & Helpers (https://forum.codeigniter.com/forum-22.html)
+--- Thread: $this->load->view() ??? (/thread-2781.html)



$this->load->view() ??? - El Forum - 08-23-2007

[eluser]CI_[/eluser]
I'm totally new to php and OOP specially in CI framework sorry for askin a stupid question like this but right now im totally mess-up... While im watching the Hello world tutorial i saw these functions... where did he get those??? were they from CI defined functions?

-------------------------------------------
<?php

class Blog extends Controller {

function index()
{
$this->load->view('blog_view');
}
}

?>
--------------------------------------------
thank you very much...


$this->load->view() ??? - El Forum - 08-24-2007

[eluser]CI_[/eluser]
hello, someone here? Big Grin


$this->load->view() ??? - El Forum - 08-24-2007

[eluser]philm[/eluser]
Have you worked throught the Introduction/General Topics section in the User Guide?

Specifically:- http://ellislab.com/codeigniter/user-guide/general/views.html

EDIT: and don't be so impatient... hehe :coolgrin:


$this->load->view() ??? - El Forum - 08-24-2007

[eluser]CI_[/eluser]
[quote author="philm" date="1187963436"]Have you worked throught the Introduction/General Topics section in the User Guide?

Specifically:- http://ellislab.com/codeigniter/user-guide/general/views.html

EDIT: and don't be so impatient... hehe :coolgrin:[/quote]

thank you very much... Smile


$this->load->view() ??? - El Forum - 08-30-2007

[eluser]Jim OHalloran[/eluser]
[quote author="CI_" date="1187938972"]where did he get those??? were they from CI defined functions?[/quote]

When you extend a class, all of the functions and variables in the class that you've extended become available to the new class (see the PHP manual for more information).

[quote author="CI_" date="1187938972"]
Code:
class Blog extends Controller {
[/quote]

This is the key line of code. The Blog class extends the basic Controller class and therefore everything from the Controller class is available via the $this variable (along with Blog specific stuff). The "load->view()" part is supplied by CodeIgniter itself, take a look at the CI manual as others have pointed out for more information.

Inheritance can be difficult to wrap your head around because all of this stuff suddenly becomes available via $this which you can't see in your code (it's in the base class), but it's extremely owerful once you're used to the idea.

Jim.


$this->load->view() ??? - El Forum - 08-31-2007

[eluser]esra[/eluser]
$this->load->view(blog);

Means load the view from the views directory called blog. If blogs was in a subdirectory under views such as views/blogs/, then you would need:

$this->load->view(blog/blog);

Entering the .php file extension is not necessary. CI handles appending the file extension for you using the EXT constant defined in index.php.

$this is the object in scope, load is an alias for the Loader library, and view is a method within the Loader library. Most files in CI are loaded by the Loader library (the notable exception being a Controller). Other examples:

$this->load->library(validation);
$this->load->helper(url);
$this->load->plugin(secureid);

Loader supports loading arrays of files (multiple files) in some cases. In Loader.php, the singular methods load individual files and the plural methods load an array of files.

Read the user guide section about the Loader library. You might want to browse through system/libraries/Loader.php to get an understanding of how Loader loads different file types.