The example in this article describes the CodeIgniter method for logging error logs. Share to everyone for your reference, specific as follows:
CI Work Flow:
All entrances are entered from the root directory index.php, after determining the directory in which the application resides, loading the codeigniter/codeigniter.php file, which loads the following files sequentially to execute the entire process.
index.php: detect file path, load codeigniter.php file
codeigniter.php: loading common/constants .... File. Get file mode, set timer, instantiate class (Error class, extension class, Hook class, System extension, configuration class, encoding class, routing class, Process class, output class, security class, language class, Controller), load request method, render output view.
A class of CodeIgniter is saved as a PHP file, the class name is the same as the filename, and its core application class is "Ci_" before the class name.
system/core/common.php: contains public functions such as checking PHP version, file permissions, loading core classes, getting configuration parameters, loading exception/error classes, getting HTTP request status, etc.
application/config/constants.php: Set file Permissions constants, application macro definition files
system/core/benchmark.php: used to record execution time
system/core/hooks.php: detect if a hook object is invoked
system/core/config.php: provides methods for managing configuration files, detecting application/config/config.php parameters
application/config/config.php: Configuring global parameters
system/core/uri.php: parsing URL parameters
system/core/router.php: detects routing configuration, resolves HTTP requests to determine who will handle
system/core/output.php: check for cached files and output directly if present.
system/core/input.php: filters HTTP requests and any user-submitted data
system/core/long.php: initializing prompt language variables
system/core/conctroller.php: Control Output class
Logging error logs:
The default program does not log error logs and can be set if necessary:
1, in the application/config/config.php set:
$config [' log_threshold '] = 1//(can be set: 1/2/3/4)
If the 0 indicates that the error log is not output, you can see the introduction in the details;
2, in the need to write the wrong page call global function log_message (' Level ', ' message '), level has three, one is error, that is, PHP run error, the second is debug, System debugging, CI itself in many pages also add their own system debug, three is info, Introduce some news in the running, the content of the message is written by itself;
3, by default, the error log stored in the application/logs/log-[time].php, it stored files by date, such as: Log-2011-6-26 said to deposit in today's log content, in general, in order to hide the contents of the log must be moved this address, you can in $ config[' Log_path '] sets the path, preferably the full path information, as required.
Set up your own global variables/configurations:
Sometimes you need to define your own whole-process variables for use elsewhere, such as custom sessions, which are also easy to work with in CI.
1, in the application/config/to create their own config file, pay attention to the location of the file. such as creating a profile of your own mysetting.php, content,
$config [' try '] = ' This is my trying ';
2. Use the $this->config->load (' settingfile ') function where a custom global variable needs to be invoked, such as:
$this->config->load (' mysetting ');
If necessary, it can also be set to load automatically via application/config/autoload.php.
3, next on the same page to use
$this->config->item (' varname ')
Functions, such as: $this->config->item (' try '); output: this is my trying;
As can be seen above,CI in the function call is: $this->filename form , can also see CI to the whole system as a large class, and then through loading, inheritance and other ways to obtain the corresponding method.
More Custom Variables Reference: http://codeigniter.org.cn/user_guide/libraries/config.html
Hide index.php and load external files:
In fact, whether CI or ZF have the same problem, is the path of the problem. In the early days, when I was using ZF as a CMS, I set up resource files such as encountering js,css,img in the. htaccess file without redirecting. But today in the use of CI, but forgot, did not do a good job, landed CI of China's official network, finally in the Forum with the help of the expert 觖, here it posted for everyone to share.
First of all, hide the index.php file in the URL so that when you access the other directories there will be no http://www.xxx.com/index.php/xxx style appearance, the face is directly http://www.xxx.com/xxx form, Set in the root directory. htaccess file (the role is to hide index.php, sometimes index.php may not be in the root directory, htaccess must move to the index.php directory), as follows:
Rewriteengine on
rewritecond $!^ (index\.php|images|js|css|robots\.txt)
#这里排除了images, JS, css directory and index.php, robots.txt file
rewriterule ^ (. *) $ index.php/$1 [L]
Here Js,css,img and other resource folders are placed at the same level as the System folder, and the benefit of an independent placement is not limited by the htaccess, because the htaccess file is denied access by stating deny from all. Open application/config/config.php Overwrite configuration:
$config [' base_url '] = "HTTP://127.0.0.1/";
$config [' index_page '] = "index.php";
If
$config [' base_url '] = http://127.0.0.1;
Not followed by '/', then the last line in Model_rewrite should write Rewriterule ^ (. *) $/index.php/$1 [L], add a '/' before index.php. Then in the JS folder to create ajax.js files, I am in the view layer of the file for index.html. So I want to introduce JS, you can use the Base_url to set the CI, as follows:
Add (before other load) in the Controllers related control page:
$this->load->helper (' url ');
In the index.html of views performance:
Copy Code code as follows:
<script type= "Text/javascript" src= "Http://sumsung753.blog.163.com/blog/<?=base_url" (). ' Js/ajax.js '?> ' ></script>
Note: Here the URL is a site relative URL (The advantage is that you can change the root directory after the relative address does not change)
Here JS folder is not redirected, so it can be normal access, and if it is restricted page is more trouble.
OK, ci in the introduction of external JS and CSS is so simple.
Note: "Rewritecond $!^ (index\.php|images|js|css|robots\.txt)" Here the code means: any resources you want to access are not redirected, can be written here. Sometimes the site is redirected when it does not load the CSS,JS (its path is correct), and it should be noted.
The Chinese official forum for CI can be viewed Http://codeigniter.org.cn/user_guide/helpers/url_helper.html,URL the Auxiliary function section,
Http://codeigniter.org.cn/user_guide/general/urls.html,url settings,
Http://codeigniter.org.cn/forums/thread-4-1-2.html,Hex about hiding index.php, but he used index\\.php in Model_rewrite, I think it's wrong to use a double back slash.
(In addition: special thanks to CI Chinese official forum hex and Visvoy)
Transmission between data:
1. Pass data from controller to view
Since the controller controllers plays a role as a traffic policeman in CI, it is a large class, and view Views act as functions in a function in the Controller class, so view can use the properties in controller. So you can write this:
Controller class Test
Class Test extends Ci_controller {public
static $test 2 = ';//define a property public
function __construct () {
Parent: : __construct ();
Self:: $test 2 = $this->load->view (' new ', ', true '); Assign value to $test2 this property
} public
function index () {
$this->load->helper (' url ');
$this->load->view (' anchor ');
}
view.php
<?php
echo Test:: $test 2;//Direct use of the values in the class
?>
This method of directly using the values in the Controllers class, although feasible, is not advocated by CI. In general, when using $this->load->view () in controller, you can pass values to the view view:
function index ()
{
$data [' css '] = $this->css;
$data [' base '] = $this->base;
$data [' mytitle '] = ' Welcome to this site ';
$data [' mytext '] = "Hello, $name, now we ' re getting dynamic!";
$this->load->view (' TestView ', $data); $data passed to view by parameter
Here, the need to pass the value to add to the $data array, CI in the core class to automatically use the Extract () function of the array "decompression" out, become a variable. So you can use variables directly in view:
2. Interaction between model and view
In CI the model is always used to process the data, the data processing in the model is also transferred to view through controller, so it is best not to try to contact the view directly with the model. There is an example in the manual:
Class Blog_controller extends Ci_controller {
function blog () {
$this->load->model (' Blog ');//Load Model
$data [' query '] = $this->blog->get_last_ten_entries ()///Use the method in the model to save the return value $data array
$this->load- >view (' blog ', $data); As in the example above, pass parameters to view views
}
}
More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"
I hope this article will help you with the PHP program design based on CodeIgniter framework.