phpcms V9 secondary development
The directory structure diagram is as follows:
In the specific modules directory of phpcms, it is the specific project module.
classes is a module class library package
functions is a module function library package
templates is a template package, where the controller template with permission control is usually placed, that is, the background template.
The foreground template is placed in the phpcms/templates/default directory
The template directory matches the controller name (or considers it yourself) .
The module controller class, placed in the module directory. When naming, it usually starts with my to indicate that it is added by secondary development.
About the creation of the module controller class:
Two types:
One: front-end browsing (without permission control)
Two: background browsing (including permission control)
The creation of the first controller class:
1. Create the mytest.php file in the module directory
write:
<?php
defined('IN_PHPCMS') or exit('No permission resource.');
class mytest{
function __construct() {
}
public function init() {
$myvar = 'hello world!';
echo $myvar;
}
public function mylist() {
$myvar = 'hello world!this is a example';
echo $myvar;
}
}
?>
About path access:
Use your project domain name:
For example: www.cms.com/index.php?m=test&c=mytest&a=mylist
m stands for module module
c stands for controller controller
a represents the action method under the specific controller
The creation of the second controller with permission control:
1. Create a file: mytest_admin.php
<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
class mytest_admin extends admin {
private $db;
public function __construct() {
}
public function init() {
$myvar = 'hi , this is my world!';
echo $myvar;
}
}
?>
References to template files (loading) :
In your controller specific method use:
include、require、include_once、require_once
Chestnuts are as follows:
include template('test','mytest','default');
About the relevant configuration of the database:
The relevant configuration of phpcms is at:
under the caches/configs directory
The database configuration file is in caches/configs/database.php
Configuration form: array form.
Chestnut:
<?php
return array (
'default' => array (
'hostname' => 'localhost',
'port' => 3306,
'database' => 'phpcmsv9',
'username' => 'root',
'password' => 'root',
'tablepre' => 'v9_',
'charset' => 'utf8',
'type' => 'mysqli',
'debug' => true,
'pconnect' => 0,
'autoconnect' => 0
),
?>
If you want to use other configurations, you can add a configuration index to the data
<?php
return array (
'default' => array (
'hostname' => 'localhost',
'port' => 3306,
'database' => 'phpcmsv9',
'username' => 'root',
'password' => 'root',
'tablepre' => 'v9_',
'charset' => 'utf8',
'type' => 'mysqli',
'debug' => true,
'pconnect' => 0,
'autoconnect' => 0
),
'mytest' => array (
'hostname' => 'localhost',
'port' => 3306,
'database' => 'demo',
'username' => 'root',
'password' => 'root',
'tablepre' => '',
'charset' => 'utf8',
'type' => 'mysqli',
'debug' => true,
'pconnect' => 0,
'autoconnect' => 0
),
);
?>
Then when using the data in the controller, you can specify what database configuration parameters are required.
Regarding using data curd in the controller:
The database model is placed under: phpcms/model directory
The name of the data model can be like this: data table name + _model.class.php
For example, to use a 'test' database, you first need to create a test_model.class.php database model file.
<?php
defined('IN_PHPCMS') or exit('No permission resource.');
pc_base::load_sys_class('model','',0);
class user_model extends model{
public function __construct() {
$this->db_config = pc_base::load_config('database');
$this->db_setting = 'mytest';
$this->table_name = 'user';
parent::__construct();
}
}
?>
The database model class name is the same as the file name
$this->db_setting = 'Specific database parameter configuration, you can use the default configuration default or customize';
$this->table_name = 'Data table name';
How to link in the controller:
<?php
defined('IN_PHPCMS') or exit('No permission resources.');
pc_base::load_app_class('admin','admin',0);
class mytest_admin extends admin {
private $db;
public function showList() {
$this->db = pc_base::load_model('user_model');
$data = $this->db->select();
print_r($data);
}
}
?>