CodeIgniter - Page Redirection

CodeIgniter - Page Redirection
When building a web application, we often need to redirect the user from one page to another. CodeIgniter makes this job easier for us. The redirect() function is used for this .
Syntax |
redirect ( $ uri = , $ method = 'auto', $ code = NULL ) |
parameters |
|
return type |
invalid |
Syntax
parameters
$uri ( string ) — URI string
$method ( string ) - redirect method ('auto', 'location' or 'refresh')
$code ( string ) - HTTP response code (usually 302 or 303)
return type
The first argument can be of two URI types. We can pass the full site URL or URI segments to the controller you want to route.
The second optional parameter can be any of three values: auto, location, or refresh. The default is auto.
The third optional parameter is only available for location redirects and allows you to send a specific HTTP response code.
example
Create a controller named Redirect_controller.php and save it to application/controller/Redirect_controller.php
Edit the route.php file in application/config/rout.php to add the route for the above controller and add the following line at the end of the file.
$route['redirect'] = 'Redirect_controller';
$route['redirect/version2'] = 'Redirect_controller/version2';
$route['redirect/computer_graphics'] = 'Redirect_controller/computer_graphics';
Enter the following URL in a browser to run the example.
http://yoursite.com/index.php/redirect
The URL above will redirect you to the tutorialspoint.com website and if you go to the following URL it will redirect you to the computer graphics tutorial at tutorialspoint.com.
http://yoursite.com/index.php/redirect/computer_graphics
CodeIgniter - Application Profiling
When building a web application, we care a lot about the performance of the website in terms of how long the controller took and how much memory is being used. Not only performance, but we also need to see the understanding of data like POST data, database query data, session data, etc. for debugging purposes while developing some kind of application. CodeIgniter made this job easier for us by profiling the application.
Enable profiling
To enable profiling of your application, simply run the below command in any of your controller methods.
$this->output->enable_profiler(TRUE);
The profiling report can be seen at the bottom of the page after it has been enabled.
Disable profiling
To disable profiling of your application, simply run the below command in any of your controller methods.
$this->output->enable_profiler(FALSE);
Enable/disable profiler section
Profiling can be done on a partition basis. You can enable or disable partition profiling by setting the boolean value to TRUE or FALSE. If you want to set up profiling within an application, you can do so in a file located at application/config/profiler.php
For example, the following command will enable query profiling for the entire application.
$config['queries'] = TRUE;
In the following table, a key is a setting that can be set in the configuration array to enable or disable a specific profile.
key |
Description |
Default |
tests |
Elapsed checkpoint time and total execution time |
TRUTH |
config |
CodeIgniterConfig Variables |
TRUTH |
controller_info |
Requested class and Controller method |
TRUTH |
receive |
Any GET data passed in the request |
TRUTH |
http_headers |
HTTP headers for the current request |
TRUTH |
memory usage |
The amount of memory consumed by the current request, in bytes |
TRUTH |
message |
Any POST data passed in the request |
TRUTH |
requests |
List of all database queries executed, including execution time |
TRUTH |
uri_string |
The URI of the current request |
TRUTH |
session_data |
Data stored in the current session |
TRUTH |
query_toggle_count |
The number of requests after which the request block will be hidden by default. |
25 |
tests
config
controller_info
receive
http_headers
memory usage
message
requests
uri_string
session_data
query_toggle_count
The profiler set in a file in application/config/profiler.php can be overridden using the set_profiler_sections() function in controllers as shown below.
$sections = array(
'config' => TRUE,
'queries' => TRUE
);
$this->output->set_profiler_sections($sections);