Use the CodeIgniter framework to quickly develop PHP applications (2)

Source: Internet
Author: User
Tags php editor
CodeIgniter has better version compatibility. It works in PHP4.3.2 or later, or PHP5. Since most ISPs do not support PHP5, it is useful to support PHP4. Two minutes: Build a CodeIgniter website

It is easy to build a website with CI. This chapter is short and explains what happened when I used CI to create a website and what files were created. let's take a look:

What software is required to create a website?

. Install the CI File: a simple download and decompression operation

. CI basic settings: What folders are there and how they are organized

Default controller and view during. CI installation

Some simple modifications to demonstrate how CI works

Prerequisites

CodeIgniter has better version compatibility. It works in PHP 4.3.2 or later, or PHP 5. Since most ISPs do not support PHP 5, it is useful to support PHP 4.

You need another database. The CI online manual says: "supported databases are MySQL, MySQLi, ms SQL, Postgre, Oracle, SQLite, and ODBC. "

To develop and test a dynamic website, you need a Web server. Generally, you develop and test your website on the local server, that is, these software runs on your own machine (127.0.0.1 or localhost). generally, the development environment is not built on a remote server.

If you are not familiar with how to create a local development environment, you can select a software package, such as Xampplite. Once you install APACHE, PHP, and MySQL, you almost do not need to modify the configuration file. Xampplite is free and has easy-to-understand installation guide.

You also need a satisfactory PHP editor. All coding can be completed in the text editor. The editor that provides the syntax highlighting function and the command auto-completion function is more ideal, because it can help programmers at a general level save time.

Once you have made these preparations, I promise you will be able to install CI within two minutes.

Install CodeIgniter

Again, CI is completely free!

After establishing the development environment, go to the CodeIgniter website:

Http://www.codeigniter.com/

And download the latest framework. Version 1.5.4 is the latest version. it is a compressed file of Only KB, which can be downloaded in seconds.

Decompress the file and release it to the root directory of the website. If you are using Xampplite, usually in the htdocs folder in the Xampplite folder.

The CodeIgniter index. php file should be in the root directory. In this case, if you open http: // 127.0.0.1 in the browser, you actually open this file. We will use 1-2 minutes to create a website that can run!

CI is a simple and easy-to-understand user manual (in the user_guide folder). you will often use it. Its content is very detailed and detailed in this article. Therefore, please refer to it frequently when necessary.

When these files are stored on your machine, there are two methods to access them:

. Through URL, http: // 127.0.0.1

. After the normal directory path: for example, C:/xampplite/htdocs/index. php

You should access the default homepage of CI through a browser. It's really simple! The default homepage sends you a message that consists of two files you are seeing: View files and controllers.

Analysis File structure

After installing the CI file, let's take a look at the directory structure.
|
-- Htdocs
|
-- System
|
| -- Application
|
| -- Config
|
| -- Controllers
|
| -- Errors
|
| -- Hooks
|
| -- Libraries
|
| -- Models
|
| -- Views
| -- Cache
|
| -- Codeigniter
|
| +-Database
|
| -- Fonts
|
| -- Helpers
|
| +-Language
|
| -- Libraires
|
| -- Logs
|
| -- Plugins
|
| +-Scaffolding
|
+-User_guide



Your root folder should now look a bit like the above chart. If you have read Rails before, this structure will look very familiar.

You can divide these folders into three groups:

. Application is the directory where your project stores files (for example, controllers, models, and Visions: all in the application folder ). except for the default views and controllers that you see, these folders are empty.

. A part of the system folder is the CI code. (System/libraries, system/codeigniter, system/drivers, etc .). If you want to, you can study them or change them-but you will not do so until you know how CI works. And if you change the code in the framework, remember to back up the code when you download the latest CodeIgniter version. Otherwise, the new version will overwrite them. Of course, you may also directly use the CI code without modifying the code yourself. the code written by Rick should be very good.

. There are some folders that contain files, but you may need to add or modify these folders (such as language, config, and errors.) to the default values, but you can modify them.

Configuration file

Remember that it would take us two minutes to build our website? You need to perform some basic settings in the next minute.

The config folder contains some files that set the basic structure for your website. Open the config/config. php file and tell the website where to find its own structure and configuration information. The first line of the file is generally like this (excluding comments ):

PHP copy code /*
| ------------------------------------------------
| Base Site URL
| ------------------------------------------------
|
| URL to your codeIgniter root. Typically this
| Will be your base URL, WITH a trailing slash:
|
| Http://www.your-site.com/
|
*/
$ Config ['base _ url'] = "http: // 127.0.0.1 /";
/* Copy the code

Note that CI comments are more detailed!

Modify the data in the quotation marks to match your own URL. If you have any questions, please query the online manual for detailed instructions.

As a basic principle, using the config. php file to store information about your website is better than spreading it across different files of your project. There are several advantages to this. First, it is easier to update. Second, it is easier to modify the configuration when you transfer the project from the development server to the actual storage server. finally, many CI functions first look for the required information in the configuration file.

Other config files are stored in the config folder, but you can use them with confidence without modifying their default values.

In two minutes, we need to build a second website. For the rest of this chapter, we will go to the website we just prepared.

Can it work?

One simple way to verify that a website works is to open your browser. If you are running it in the root folder of the local server, enter http: // 127.0.0.1 in the address bar to view the default page of the website.

Seeing the default page means that your website is working properly. It does not take two minutes, right?

Summary

In this section, we have seen how easy it is to install CI. Once your development environment is established, all you need to do is download the CI framework file, decompress it, and copy it to a directory.

Then, we quickly browsed the CI directory structure.

This section is very short, because CI is easy to install and does not require too long space. In fact, other chapters are not long, because CI is really easy to understand and saves time.

Chapter 3:

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.