Rapid development of PHP applications using the CodeIgniter Framework (ii)

Source: Internet
Author: User
Tags php editor codeigniter

Text: Rapid development of PHP applications using the CodeIgniter Framework (ii)

Two minutes: Build a CodeIgniter website

It's easy to build a website with CI. This chapter is short and explains what happens when you make a website with CI, what files are created, let's take a look:

. What software is needed to create a website?

. Install CI file: A simple download and decompression operation

. Basic settings for CI: What folders and how they are organized

. Default controller and view for CI installation

. A few simple changes to demonstrate how CI works

Prepare knowledge

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

You also need a database. CI's online handbook says: "The supported databases are MySQL, mysqli, MS SQL, Postgre, Oracle, SQLite, and ODBC." "

In order to develop and test a dynamic Web site, you need a Web server. Typically, you will develop and test your site on a local server, which means that the software runs on your own machine (127.0.0.1 or localhost), and generally, the development environment is not built on a remote server.

If you are unfamiliar with how to build a local development environment, you can choose a suite of software, like Xampplite, to install Apache, PHP, and MySQL at once, with little need to modify the settings file. Xampplite is free and has easy-to-understand installation instructions.

You also need a satisfying PHP editor. All the coding work can be done in a text editor. An editor that provides syntax highlighting and command auto-completion can be more desirable because it helps average programmers save time.

Once you're done with these preparations, I guarantee you'll be able to handle the CI installation in two minutes.

Installing CodeIgniter

Again, CI is completely free!

After establishing the development environment, go to CodeIgniter website:

http://www.codeigniter.com/

and download the latest version of the framework. 1.5.4 version is the latest version, is a only 737KB of compressed files, a few seconds can be downloaded to complete.

Unzip the file and release it to the root directory of the Web site. If you are using Xampplite, usually the Htdocs folder inside the Xampplite folder.

The CodeIgniter index.php file should be in the root directory. At this point, if you open http://127.0.0.1 on the browser. You have actually opened this file. It takes us 1-2 minutes to build a Web site that works!

And CI are included together as a user manual that is easy to understand. (In the User_guide folder) you will often use it. Its content is very detailed, fine over this article, so, when needed, please check it frequently.

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

. by url,http://127.0.0.1

. After a normal directory path: for example, c:/xampplite/htdocs/index.php

You should access the default homepage of CI through the browser. It's simple! The default home page is passed to you with a message: it is made up of two files you are seeing that are composed of two documents: View files and controllers.

Analyze file structure

After installing the CI file, let's 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 chart above. If you've ever looked at rails, this structure will look very familiar.

You can divide these folders into three groups:

. Application is your own directory of project storage files (for example, controller, model, and field of view: All in the App folder). Except for the default views and controllers that you've seen, these folders are empty.

. Part of the folder in the System folder is the code for the CI itself. (System/libraries, System/codeigniter, system/drivers, etc.). ). If you want, you can read them or change them-but wait until you understand how CI works. And if you change the code inside the frame, remember to back them up when you download the CodeIgniter update version. Otherwise, the new version overwrites them. Of course, you may not need to modify the code and directly use the CI itself code, Rick wrote the code should be very good.

. Some folders already contain files, but may need to be added or modified (such as: Language, config, errors). These folders are set to default values, but you can modify them.

Configuration file

Do you remember that we took two minutes to build our website? The second minute is used to make some basic settings.

The Config folder contains some files that set the basic structure for your site. Open the config/config.php file. Tell the site where it should find its own structure and configuration information. The first line of the file is typically this (without comments):

Php/ *
| Base Site url
|----------------------------------------- -------
| URL to your CodeIgniter root. Typically THIS
| would be your base URL, with a trailing slash:< BR style= "Word-wrap:break-word; Line-height:normal; ">|
|
*/
$config[' Base_url ']="HTTP://127.0.0.1/";
/*Copy Code

Note the CI notes in more detail!

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

As a basic principle, using the config.php file to store information about your site is better than distributing it across different files in your project. There are several advantages to doing so, first, updating is easier; second, it is easier to modify the configuration when you move the project from the development server to the actual storage server, and finally, many of the CI functions first look for the required information in the configuration file.

There are other config files in the Config folder, but for now you can use them with confidence without having to modify their default values.

In two minutes, we need to build a second website. In the remainder of this chapter, we will be visiting the website we have just done.

Can it work?

An easy way to verify that your Web site works is to open your browser. Assuming you are running it in the root folder of the local server, enter http://127.0.0.1 in the Address bar and you can see the default page of the site.

Seeing the default page means your site is working properly. It doesn't take two minutes, does it?

Summary

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

Later, we quickly browsed the directory structure of CI.

This section is very short because CI is easy to install and does not need to be lengthy. In fact, the other chapters are not long, because CI is really easy to understand, save time.

Rapid development of PHP applications using the CodeIgniter Framework (ii)

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.