Phpcms V9 Full Development introduction

Source: Internet
Author: User
Tags domain transfer


Phpcms V9 file directory structure:
root directory
| –api Interface File directory
| –caches Cache file Directory
| –configs System Configuration file directory
| –caches_* System Cache Directory
| –PHPCMS PHPCMS Framework Home Directory
| –languages Framework Language Pack Directory
| –libs Framework main class library, main function library directory
| –model Framework Database Model Catalog
| –modules Framework Module Catalog
| –templates Framework System Template Catalog
| –phpsso_server Phpsso Home Directory
| –statics System Accessory Kit
| –CSS System CSS Package
| –images System Picture Package
| –js System JS Package
| –uploadfile Website Accessories Directory
| –admin.php Backstage Management Portal
| –index.php Program main Entrance
| –crossdomain.xml Flash cross-domain transfer files
| –robots.txt search engine Spider restriction profile
| –favicon.ico System icon

2.url Access
Parameter Name Description Location remarks
M model/Module name phpcms/modules The module directory name must be
C Controller name phpcms/modules/module/*.php file name must be
A event name phpcms/modules/the method name in module/*.php

Eg:http://yourdomain.com/index.php?m=content&c=index&a=show&id=1
m = content for model/module name in Phpcms/modules/content
c = Index is the controller name in phpcms/modules/content/index.php
A = Show is the time name in phpcms/modules/content/index.php in the Show () method
ID = 1 is the same as the normal get pass parameter for other parameters
If we visit your domain name such as: http://www.yourdomain.com/index.php
The PHPCMS default route locates the init operation in the Content module's index controller because the system executes the default modules and operations when no modules and controllers are specified. So the result of the following URL is the same:
The system also supports URL routing, which can bring other URL http://www.yourdomain.com/index.php?m=content&c=index&a=init effects as well.
3. System class library and function library call
1. The System class library is located under the system's Phpcms/libs/classes directory, the function library file name is *.class.php, where global.func.php is loaded by default in the framework, global.func.php function can be used directly

2. The System function library is located under the system's Phpcms/libs/functions directory, the function library file is named *.func.php

System Class Library calls:
$http = Pc_base::load_sys_class (' http '); Instantiating an HTTP class
Pc_base::load_sys_class (' Format ', ', 0); Calling the form class without instantiating the operation

system function Library calls:
Pc_base::load_sys_func (' Mail '); Calling the Mail function package
PHPCMS Naming conventions:
class files need to be suffixed with. class.php (here refers to the PHPCMS system class library files and class library files in the module, the third party introduces no requirements), such as http.class.php.
The function file needs to be suffixed with. func.php (third-party-introduced non-requirements), such as mail.func.php.
The class name and file name are identical, for example the file name of the Phpcmsapp class is phpcmsapp.class.php.
The data model needs to be in the form of "data table name _model.class.php" and the class name must be the same as the file name.

4. configuration file Invocation:
Configuration files are configured under the caches/configs/directory.
Configuration file invocation: Using the Load_config method
$upload _url = pc_base::load_config (' System ', ' upload_url ');

5. Two-time development tips:
1. If you want to develop the existing controller two times, in order to facilitate the upgrade is not recommended directly to the kernel file directly modified, you can be "my_*.php" in the form of two development.
For example, you need to develop two times to change phpcms/mood/index.php. You can create "my_index.php" in a directory similar to index.php
The my_index.php code is as follows
<?php
Class My_index extends index{
function __construct () {
Parent::__construct ();
}


... your code
}
?>
This way, when you access the index controller through a URL, the system will default to my_index.php and the original file method will be inherited and can be used directly. Inheritance

Configuration:
1. Database configuration:
Database configuration file Location: caches/configs/database.php
We open this configuration file and add our database configuration information. The database configuration information is a two-dimensional array structure that defaults to default and can be configured with multiple database links based on the default structure (for example: extended_1)
2. Routing Configuration
Routing configuration file location: caches/configs/route.php
We open this configuration file and add our routing configuration information. The routing configuration information is a two-dimensional array structure that defaults to default.
3. System Configuration
System configuration File Location: caches/configs/system.php

To add a template call to the controller:
Phpcms can achieve a complete separation of the template and the program, so in our controller program to load the template, can be more friendly display.
1. Loading the foreground template
The foreground template file is in the Phpcms\templates\default\ module name directory, and this example is also in Phpcms\templates\default\test
Here's how to load the template:
Include template (' Test ', ' mytest ', ' Default ');
Where test is the module name mytest is the template directory under the template name, default is the style name, is not filled with defalut
2. Loading the background template
The background template file is in the Phpcms\modules\ module name \templates directory, and This example also loads the template method in Phpcms\modules\test\templates as follows:
Include $this->admin_tpl (' mytest_admin_list ');
Where Mytest_admin_list is mytest_admin_list.tpl.php in phpcms\modules\test\templates, note: Here the template must be suffixed with. tpl.php

Data Model classes:
The database model is located in the: phpcms/model/directory. Naming rules for data model files recommended for data table "+ ' _model.class.php ' if in our created module I want to use a database" test ", first need to establish a database model file, the file name is called ' test_model.class.php '
<?php
Defined (' In_phpcms ') or exit (' No permission resources. ');
Pc_base::load_sys_class (' model ', ', 0);
Class Test_model extends Model {
Public Function __construct () {
$this->db_config = pc_base::load_config (' database ');
$this->db_setting = ' default ';
$this->table_name = ' Test ';
Parent::__construct ();
}
}
?>
Attention:
1. The database model class name must be the same as the file name;
2. $this->db_setting = ' Default ' to configure the database link pool name in the database configuration file, default defaults, no modification is normally required.
3. $this->table_name = ' test ' for the data table name
Used in the controller:
<?php
Defined (' In_phpcms ') or exit (' No permission resources. ');
Class MyTest {
Private $db;
function __construct () {
$this->db = Pc_base::load_model (' Test_model ');
}
Public Function init () {
$result = $this->db->select ();
Var_dump ($result);
}
}
?>

Template Label use:
Common:
{pc:get sql= "select * from Phpcms_member" cache= "3600" page= "$page" dbsource= "Discuz" return= "Data"}
<ul>
{Loop $data $key $val}
{$val [username]}<br/>
{/loop}
</ul>
{$pages}
{/PC}


Development process

The general development process for creating a module for your phpcms is:

Create database and data tables; (No database operations can be skipped)
Create a Module Catalog
Create a module controller class;
Create module classes and module functions (if only simple modules can not be created)
Create template files;
Run and Debug.

Phpcms V9 Full Development introduction

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.