# Loader

The loader class is the one in charge of loading the models, views, controllers, languages and libraries in Wolff.

Any controller and model that is instantiated already comes with its loader named 'load'.

Controller

Loading a controller is done in the same way:

$this->load->controller('home');

If it’s in a subfolder:

$this->load->controller('subfolder/home');

This will load the home controller, if no function is specified, the index function of the corresponding controller will be executed.

So you can load a controller function this way:

$this->load->controller('home/sayHi');

This will load the home controller and execute its sayHi function instead of index.

Function

You can load and get the value returned by a controller method using the function method.

$this->load->function('[email protected]');

That will load the getUsers method of the user controller and return its value.

The controller and method name must be separated by a @.

View

For the views it is the same:

$this->load->view('home');

This will load the home.html file inside the app/view folder, if the file with html extension doesn't exists, the loader will try with the php extension (in this case equivalent to app/view/home.php).

Sending data

You can pass data to the view using an array like this:

$data['msg'] = 'Hello world';

$this->load->view('home', $data);

So instead of this way:

<?php echo $data['msg']; ?>

You can use the data in the view this way:

<?php echo $msg; ?>

Or even better, use the template system of Wolff:

{{ $msg }}

Cache

The views use by default a cache system, when loading a view a file titled tmp_{fileDirectory}.php will be created in the cache folder if it doesn't exists already, so the view will be loader from that file and any change made to the original file will not be displayed.

You can perfectly refresh the cache deleting the cache folder content.

If you want to force a view to don't use the cache system, you can pass a false value to the loader view function as the third parameter.

$this->load->view('home', $data, false);

This will force that view to don't use the cache system, keep in mind that the loading time could increase due to this.

getView

Returns the view content without being rendered.

$data['sidebar'] = $this->load->getView('home', $data);

getRender

Returns the view content already rendered.

$data['sidebar'] = $this->load->getRender('home', $data);

Language

When calling the language function of the loader, the data array of the language file is returned. You can load a language this way:

$this->load->language('home');

The language file path is determined by the language constant established in the config.php file:

define('LANGUAGE', 'english');

If the language constant is english, it will look for the app/language/english/home.php file. Otherwise, if the language constant is español it will look for the app/language/español/home.php file.

You can also specify a different language when loading it if you want, like this:

$this->load->language('home', 'español');

This will load the spanish language for home no matter the language constant specified in the config.php file.

You can create multiple folders for multiple languages in the app/language folder.

So you can have a home language file like this:

$data['header'] = 'Wolff';
$data['message'] = 'This is ridiculously small';

And in the controller you can get it this way:

$data['language'] = $this->load->language('home');

After that you can load the view in the controller:

$this->load->view('home', $data);

And finally in the view you can do this:

<?php echo $language['header']; ?>
<?php echo $language['message']; ?>