CI_Loader::view()

view($view[, $vars = array()[, return = FALSE]])

Parameters:
  • $view (string) – View name
  • $vars (array) – An associative array of variables
  • $return (bool) – Whether to return the loaded view
Returns:

View content string if $return is set to TRUE, otherwise CI_Loader instance (method chaining)

Return type:

mixed

This method is used to load your View files. If you haven’t read the Views section of the user guide it is recommended that you do since it shows you how this method is typically used.

The first parameter is required. It is the name of the view file you would like to load.

Note

The .php file extension does not need to be specified unless you use something other than .php.

The second optional parameter can take an associative array or an object as input, which it runs through the PHP extract() function to convert to variables that can be used in your view files. Again, read the Views page to learn how this might be useful.

The third optional parameter lets you change the behavior of the method so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to TRUE (boolean) it will return data. The default behavior is FALSE, which sends it to your browser. Remember to assign it to a variable if you want the data returned:

$string = $this->load->view('myfile', '', TRUE);
doc_CodeIgniter
2016-10-15 16:31:46
Comments
Leave a Comment

Please login to continue.