PHPCMF + php + diary (1)

Source: Internet
Author: User
: This article mainly introduces PHPCMF + php + diary (1). If you are interested in the PHP Tutorial, please refer to it. Today is the first time I learned about PHP. because PHP is used in the background and PHPCMF is an open-source framework, I have to get myself started,

However, it is indeed convenient to write PHP back-end, which is faster than java. Aside from other factors, I only want to test speed.

Maybe I have never learned the syntax of PHP, and I am directly connected to PHPCMF. so I should first look for someone to familiarize myself with the use of the framework.

I am most concerned about how to quickly build a module with PHPCMF.

Well, let's just talk about it.

First, import the official phpcmf download package to the zend editor. If an error occurs, do not worry about it. there is no way for x-sensitive users, as shown below:

What we care about is the four folders above, so we can quickly get started,

(1) application folder

If I want to create a News module, the first thing we need to do is to create a News folder under the application, as shown below:

Other folders are built-in and don't worry. Next, you need to know what else we need?

The controller, right, is the controller. this is very important in PHP. if you don't know how to build it, if you are just starting with me, then you can look at any other folder under the application. for example, there is a Controller folder under the User folder, and we also need to create such a folder.

See No. we only need to create a Controller with the same folder. you don't need to worry about the others. for example, the Conf and Menu folders are currently unavailable and you don't need to worry about it. the folders have been created, next, we need to write the interface, that is, create a php file under the Controller folder, but the interface can be divided into front-end and back-end, for example, there is a front-end display of news, there are background editing, adding, deleting, modifying, and so on. we need to care about this, and there are certain requirements for naming,

Let's take a look at the two php files I created under News. First, let's talk about the naming rules,

First, you can give a name and add Controller. class. if this interface is a background interface, you need to add AdminController. class,

Next, we need to know how to write this class file,

The first step is required by the namespace Module Name \ Controller

The second step is to declare who the parent class is. if the interface is front-end, you will use HomeBaseController. if the interface is back-end, you will use AdminbaseController, as shown in:

Step 3: Create a class, class NewsController extends HomeBaseController {}

Step 4 is to write the method in the class, that is, the interface. for example, I wrote getNewsList () and finally echo the returned data.

At this point, the application is half done. nothing happens. I also draw a circle on the graph, that is, the address used to access this interface, and its structure is quite understandable.

// Www.fsfd.com/XXXX/index.php? G = News & m = News & a = getNewsList

Where www.fsfd.com/is the domain name public network IP, xxxx/ is the project name, is the project name, index. php? This is fixed. there is this file under the project name. you don't need to change anything. g = News indicates which folder under the application, that is, which module, & m = News this code refers to the last section (NewsController. class. php). you can use this name as needed. & a = getNewsList indicates the method below this class. Next, we need to be familiar with the other half of the application that is also in our comparative relationship, database,

There is a Common folder under the application file, and there is a Model folder under it, which is the Model folder we need to care about. In fact, each model file below represents a table in the database,

Let's first look at what the built-in model is, such as User

The first step is the namespace Common \ Model;

The second step is to declare the parent class, use Common \ Model \ CommonModel;

The third step is to define the class UsersModel extends CommonModel {}. you do not need to worry about the content in it. the User we can see is data verification and time conversion, it seems that the password is being processed, and I cannot understand it now. it seems that I don't need to think about the field definitions required for connecting data, and so on,

Then we need to write our own statement. it's just a statement.

This is the end. php will match your MySQL database. The Parsing method is as follows. Data tables have a prefix followed by a lower-case table name, the name of a database table. for example, the table in my database is wust_news. then, under the Model, you must be consistent with the second half of the database table field, only the first letter is capitalized, so that it will automatically parse and match successfully,

So far, the application has ended.

(2) data folder

This is actually nothing to say. I know the English name. data is stored under this folder, such as cached data. in the runtime file, the images you upload on the background management interface, video, etc. you can create a folder here. in the conf folder, there are route settings. I don't understand the specific settings. it seems that you don't need to manually set this, you don't need to mention anything here.

(3) tpl folder

Put the folder of the front-end template and you will understand it. for example, if you open a webpage and put the displayed content in it, you can mainly look at its hierarchy.

This mainly depends on the modules under the application. compared with the Controller folder under the module, the tpl folder also has this, one for the client and one for the mobile phone, next let's take a look at what is under the User. Note that the names must be consistent,

The above Red × does not mean an error. it is just like importing it in. Don't worry about it. the final code we write is to upload it to the server, so there will be no error, there is no way to be sensitive, huh, huh, first we need to look at the Controller under the User folder under the application folder, we can look at a class, CenterController Personal Center, note: $ this-> display (); and $ this-> display (': Center'). you can use either of the following two cases: in this case, center.html appears in the lower-end user folder of tplicate,

If it is $ this-> display (); then you need to first check the controller name, and then create the folder with the first half of the name under the User, with the first letter in upper case, then, you can see the html file with the same name as the method below,

The figure should be clear. This part is over now,

(4) tpl_admin background management module

For this part, please refer to (3) the things that are specially placed in the background management here. the situation is the same as that of the tpl folder, so we will not look at books anymore.

Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.

The above introduces PHPCMF + php + diary (1), including some content, and hopes to help those who are interested in PHP tutorials.

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.