Notes on basic configuration of CI framework in php

Source: Internet
Author: User
Tags autoload character set error handling php server regular expression codeigniter

Let's take a look at the ci preparation ..

First, you need to change its default page.

The default access is welcome. php. We have to change it to our own access page.
In this case, the application --> config --> routes. php page
$ Route ['default _ controller'] = "***";
In the config. Php file
$ Config ['base _ url'] = '***'; website address
$ Config ['index _ page'] = 'index. Php'; default method name for access
Enable the key if sessionde is used.
$ Config ['encryption _ key'] = '*****';
And so on ..
Continue in the autoload. Php file
$ Autoload ['libraries'] = array ('***'); load the class to be used
$ Autoload ['helper '] = array (' *** '); loads the necessary auxiliary functions
Remember

Also configure. htacces...

The code is as follows: Copy code
RewriteEngine on
RewriteCond $1! ^ (Index & yen;. php | images | robots&yen=.txt)
RewriteRule ^ (. *) $/index. php/$1 [L]

Any HTTP requests except index.php, images, and robots.txt are treated as requests to the index. php file.

One tester

Use CI to manage databases
Application/config/routes. php: $ route ['scaffolding _ trigger'] = "zhougege ";
Add $ this-> load-> scaffolding ('Marry _ user_profile ') to your controller constructor ');
You can access http: // localhost/yourclass/zhougege to manage your database.
CI error handling
Index. php displays all errors by default: error_reporting (E_ALL );
Show_error ('message') function. The error information is displayed by application/errors/error_general.php as the template.
Show_404 ('page') function. Press application/errors/error_404.php as the template to display a 404 error.
The log_message ('level', 'message') function writes error messages to error logs. You must provide error levels (three types) in the first parameter to indicate the levels of errors (debug, error, info). The second parameter is the error information.

Okay, the entire example.

The basic configuration information of CodeIgniter is in the application/config. php file. This article describes each basic configuration option in detail to quickly master CodeIgniter for development.

The code is as follows: Copy code

$ Config ['base _ url'] = "http://www.111cn.net /". The URL of your website. CodeIgniter generates links and form addresses based on the URL.

$ Config ['index _ page'] = "index. php": name of the index. php file under the CodeIgniter root directory. CodeIgniter uses this file to generate a link address. If you use the URL to hide index. php, set it to an empty string: $ config ['index _ page'] = "".

$ Config ['uri _ protocol'] = "AUTO" CodeIgniter: format used to generate the URL. Set it to "AUTO" for automatic detection. If the link does not work properly, try the following values: PATH_INFO, QUERY_STRING, REQUEST_URI, and ORIG_PATH_INFO.

$ Config ['url _ suffix '] = "". The URL suffix used by CodeIgniter to generate a link. To implement pseudo-static state, you can set $ config ['url _ suffix '] = ". html ".

$ Config ['language'] = "english ". Default CodeIgniter language

$ Config ['charset'] = "UTF-8 ". Default character set used by the CodeIgniter program

$ Config ['enable _ Hooks'] = FALSE. Whether to enable the hook function. The Hook function allows you to change or add the core running function of the system without modifying the core file of the system.

$ Config ['subclass _ prefix'] = 'My _'. Set the class name prefix used to extend the CodeIgniter class library

$ Config ['permitted _ uri_chars'] = 'A-z 0-9 ~ % .:_-'. Set the characters allowed in the CodeIgniter URL. This is a regular expression. When a visitor attempts to access a CodeIgniter URL that contains other characters, a warning is given. We recommend that you restrict the characters used by CodeIgniter URLs to improve security and effectively filter injection attacks. If it is set to Null, all characters are allowed. We strongly recommend that you do not do this.

$ Config ['enable _ query_strings '] = FALSE. CodeIgniter URLs use segmented URLs by default. This option also allows CodeIgniter to enable string-based URL query. You can use query strings to pass the controllers and functions to be accessed. For example, index. php? C = controller & m = method. CodeIgniter uses segmented URLs by default. Many features of string URL query are not supported.

$ Config ['Controller _ trigger'] = 'C '. CodeIgniter treats the value corresponding to this option in the query string as the name of the CodeIgniter controller.

$ Config ['function _ trigger'] = 'M '. CodeIgniter treats the value corresponding to this option in the query string as the name of the CodeIgniter controller method.

$ Config ['log _ threshold '] = 0. Enable error logs and set the types of errors to be recorded.

0 = disable error logging
1 = record error information
2 = record debugging information
3 = record notification information
4 = record all information
$ Config ['log _ path'] = "". If you do not want to use the default error log Directory configuration (system/logs/), you can set the complete server directory.

$ Config ['log _ date_format'] = 'Y-m-d H: I: s '. CodeIgniter error log time format

$ Config ['cache _ path'] = "". If you do not want to use the default cache Directory (system/cache/) to store the cache, you can set the complete server directory

$ Config ['encryption _ key'] = "". Key used by CodeIgniter

$ Config ['global _ xss_filtering '] = FALSE. Whether to automatically filter cross-script attacks against input data (GET and POST)

$ Config ['compress _ output'] = FALSE. Enable Gzip compression to achieve the fastest page loading speed

$ Config ['time _ reference '] = 'local '. Set the time format: "local", "GMT"

$ Config ['rewrite _ short_tags'] = FALSE. If you want to use the short tag, but not supported by the PHP Server, CodeIgniter can rewrite the short tag to support this function.

$ Config ['proxy _ IP'] = "". If a visitor accesses your website through a proxy server, you must set a proxy server IP list to identify the visitor's real IP address.

Custom simple control class

The code is as follows: Copy code
<? Php
Class Blog extends Controller {
Function index ()
{
Echo 'Hello World! ';
}
}
?>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.