I have a very basic code below i am new to code igniter so pardon if my question sound amateur
public function view($num = 0) {
echo "View was called<br>";
$this->load->view("header");
$this->load->view('xyz');
$this->load->view('footer');
echo "View function ended";
}
Ok so i want to know why code igniter doesn't output result the way it is return
The ouptut of the code is as following
- View was called
- output of the result by calling random_func()
- Renders view
What is expected from the output is as following
- View was called
- Renders view
- output of the result by calling random_func()
Is there any code igniter specific behavior i am missing on?why code igniter holding the views in buffer ?
If you follow Codeigniters lifecycle in /system/core/Codeigniter.php
you will see that the final output gets called near the very end of the file.
So views will always get output to the browser last, regardless of how they are called.
When a view is called, it gets stored in the buffer so it can be manipulated before it gets sent for final render.
Manipulating the buffer could be anything from storing one view in another, parsing/injecting variable data/tags etc.
Codeingiter Lifecycle(in Order)
- Defines some Global Constants(CI_VERSION, CI_CORE) version control
- Loads the core/Common.php file which includes some GLOBAL helper
functions
- Checks which ENVIRONMENT the framework is running
under(local/remote)
- Sets a Custom Error handler for handling Errors/Exceptions
- Loads the config file to check if there is a custom subclass prefix
eg: (MY_)
- Set a liberal script execution time limit
- Loads the Benchmark class so anything under this line can be
benchmarked!
- Loads the hOOk class and checks if their are any 'pre_system' hooks
defined in application/hooks
- Loads the main config file and assigns everything inside the file to
the config array
- loads the UTF-8 and URI classes
- Loads the router class and sets the default route in
/application/config/routes.php => default_controller
- loads the output class and checks if there is anything in the cache
that can be output straightaway
- loads security/Input/lang classes
- Loads the Controller class(entry point) and sub classes that extend
it in application/controllers
- checks to see if a Controller method begins with and _ => this is
private
- Does some other security checks and looks for an index method in
the controller and searches for requested controller
- looks for a pre_controller Hook
- Instantiates the requested controller from step 16
- looks for a post_controller_construct Hook
- looks for a controller _remap override function
- looks for a post_controller Hook, this happens after the controller
__construct method has been called
- Outputs the final Render(buffer) to the browser
- looks for a post_system Hook
- Closes any DB Connections that are open
- Back to step 1
As you can see now from the cycle, If you wanted to intercept it at any point, you would created a HOOK, and those hooks will get injected at the point the hooks are called.
Hope this helps