today is the first time to learn PHP because the background is written in PHP, and is used by the open source framework PHPCMF so I have to come to a bad ah,
However, PHP writing background is really convenient, faster than Java, the first aside the other factors to speed, just test
Maybe I study PHP is dabbler on the road, even grammar have not studied, direct contact with PHPCMF, so first find someone familiar with the use of the framework
How to build a module quickly with PHPCMF is my most concern.
Okay, cut the crap and go straight to the chase.
First PHPCMF the official download package into the Zend Editor, the error does not care about it, there is no way for the x -sensitive person, as follows:
We are concerned about the above four folders, you can quickly start, the others do not have to control the first,
(a) Application Folder
If I need to make a news module now, the first thing we need to do is create a new news folder under Application, as follows:
The other folders are self-bringing, no tube, and then you need to know what else we have?
Controller, right, is the controller, in PHP This is very important, if you do not know how to build, if you are just beginning with me, then you can look at any other application under the folder, such as user it has a controller folder, We also need to build a folder like this.
See no, we just need to build a folder controller, the other first without the tube, such as Conf and Menu folder currently not used, no tube, completed the folder, next we need to write interface, is in the Controller folder under the creation of a PHP file can be, but the interface is divided into front and back, such as the front of the news display, there are backstage edits and additions to change and so on, we need to care about this, and the name has a certain requirements,
See news below is the two PHP files I created, first of all, the question of naming rules,
First of all you can take a name, and then add Controller.class, if the interface is a background interface, then you need to add admincontroller.class this is very important,
The next thing you need to know is how to write this kind of file.
The first step is the namespace must have, namespace module name \controller
The second step is to affirm who the parent class is, if the interface is front-end, you use Homebasecontroller, if the interface is behind the scenes, you use Adminbasecontroller as shown:
The third step is to create a class Newscontroller extends homebasecontroller{}
The fourth step is to write the method in the class, that is, the interface, for example, I wrote above is Getnewslist () finally to return the data echo on the line
At this point application ended half, nothing, I also draw a circle, is to access the address of this interface, its structure is also very good understanding
Www.fsfd.com/XXXX/index.php?g=News&m=News&a=getNewsList
Where www.fsfd.com/ is the domain name or public network IP,xxxx/is the project name, is the project name,index.php? This is fixed, under the project name has this file, do not change what,g=news This represents application under which folder, which module,&m=news This code you create in the Controller folder under the php file that named the first paragraph (NewsController.class.php), the name can be casually up,&a= Getnewslist this represents the following method for this class. The next step is to get acquainted with the other half of the application that we are comparing, the database ,
Under the application file has a common folder, it also has a model folder below, that is, this model folder is what we need to care about, in fact, each of the following model file is represented in the database of a table,
Let's start by looking at what the model is all about, like user
The first step or the namespace, namespace Common\model;
The second step is to affirm the parent class, use Common\model\commonmodel;
The third step is the class definition of class Usersmodel extends commonmodel{}, the inside of the things do not need to control it, you can see the user below is the data validation, time conversion, as if the password to deal with, anyway, I do not understand now, It doesn't seem like we need to think about the kind of field definitions that are needed to connect to the data.
Then we need to write our own, very simple is a statement
So the end, PHP itself will be matched with your MySQL, it parses the way it is, the data table has a prefix, followed by a lowercase table name, together form a database table name, for example, my database table is Wust_news, Then the model below you must be consistent with the second half of the database table field, but the initial capitalization is OK, so that he automatically parse and match the success,
This application is over.
(ii) Data folder
This actually nothing to say, see the English name also know, the folder below is the data, such as the cache data, in the runtime file, you upload images in the background management interface, video Ah, etc. can be built in this folder, in the Conf folder below is the routing settings, the specific I do not understand, It's like saying this doesn't have to be set up manually, and there's no need to say anything specifically.
(iii) TPL folder
Put the front-end template folder, say you know, for example, you open a Web page, the display of things placed in this, mainly to look at his hierarchical structure
This is mainly to see application below what modules, compared to the module below must have controller this folder, then this TPL folder there is this, one is the client, a mobile phone, below we see what the user below, note the name to be consistent,
The above red X does not mean the wrong, is imported in this way, do not control it, we finally write the code is to upload to the server, he is not wrong, there is no way sensitive people, hehe, First we need to look at the controller under the user folder under the Application folder, we casually lookat a class, center controller Personal Centre, note $this->display (); $this->display (': Center '); In both cases, use: This thing, then under the user folder below the TPL must have center.html in the next level,
If it is $this->display (); So the first thing you need to see the name of the controller, and then to the user under the name of the first half of the folder, the first letter capitalized, and then below, you can see the method name consistent with the HTML file,
Look at the picture should be very clear, so this part is over,
(d) Tpl_admin backstage Management module
In this section please see (iii) Here is a special background management, the situation with the TPL folder, it is no longer redundant books
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
The above describes the Phpcmf+php+ Diary (a), including the aspects of the content, I hope that the PHP tutorial interested in a friend helpful.