Does phpcms have a controller?
phpcms has controllers. The phpcms controller is the class file of the module, which is stored under "phpcms/modules". Each module has an independent naming method. The class name is in the format of "filename.php naming"; the controller class inherits the system's function library by default. Can be used directly. The class name of the controller class and the controller file name must be the same.
The operating environment of this tutorial: windows7 system, phpcms v9 version, DELL G3 computer
phpcms has a controller.
What is a controller in phpcms
phpcms controller is the class file of the module, which is stored under phpcms/modules. Each module has an independent naming method. The class name is in the file name.php naming format. The controller class inherits the system's function library by default and can be used directly. The class name of the controller class and the controller file name must be the same.
Add a new controller
Next we will create a new test folder under phpcms/modules, and create a new one named mytest.php in the test folder file, add the following code in the file:
defined('IN_PHPCMS') or exit('No permission resources.');class mytest { function __construct() { } public function init() { $myvar = '这是默认加载!'; echo $myvar; } public function mylist() { $myvar = '这是自定义list!'; echo $myvar; } }
Then we can enter the following access method in the browser
http://domain name/index.php?m=test&c= mytest
The init() method is loaded by default
http://domain name/index.php?m=test&c=mytest&a=mylist
Loading is the mylist method
Template introduction
Front-end template
Website front-end template location Under the phpcms/templates/default/ module
We add the loading template method in the init() method of the controller mytest.php file
include template('test', 'mytest', 'default');
Create a new one under the phpcms/templates/default/ directory The test folder and mytest.html file are enough.
Backend template
The background template file is in the phpcms/modules/module name/templates directory
Controller with permissions
Backend controller
Create a new mytest_admin.php file under phpcms/modules/admin/. The file code is as follows:
defined('IN_PHPCMS') or exit('No permission resources.'); pc_base::load_app_class('admin','admin',0); class mytest_admin extends admin{ function __construct() { } public function index(){ echo "后台控制器"; } }
Access address: http://domain name /index.php?m=admin&c=mytest_admin&a=index
phpcms custom model
Introduce the model on the class
pc_base::load_sys_class('model', '', 0);
Then the class extends inheritance model
Add the following code in the __construct method:
$this->db_config = pc_base::load_config('database'); $this->db_setting = 'default'; parent::__construct();
Query statement
function init(){ $sql = 'select * from v9_news '; $data = $this->get_array_by_sql($sql); var_dump($data); } public function sql_query($sql) { if (!empty($this->db_tablepre)) $sql = str_replace('phpcms_', $this->db_tablepre, $sql); return parent::query($sql); } public function fetch_next() { return $this->db->fetch_next(); } //通过SQL语句查询一条结果 public function get_one_by_sql($sql){ $this->sql_query($sql); $res = $this->fetch_next(); $this->free_result(); return $res; } //通过sql语句查询数组 public function get_array_by_sql($sql){ $this->sql_query($sql); $res = $this->fetch_array(); $this->free_result(); return $res; } //释放数据库结果资源,调用底层完成 public function free_result() { $this->db->free_result(); }
PHP Chinese website, a large number of free PHPCMS tutorials , welcome to online learning!
The above is the detailed content of Does phpcms have a controller?. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











The benefits brought by the integration of PHP framework and CMS are: 1. Improve development efficiency; 2. Enhance security; 3. Simplify content management; 4. Flexibility. In a practical case, the Laravel framework was integrated with WordPressCMS to create a blog website with customized functions. The integration steps include creating a Laravel application, installing WordPress, configuring WordPress, creating a controller, defining routing, obtaining WordPress data, and in the Laravel view Display Data.

PHP CMS is a PHP-based open source content management system for managing website content. Its features include ease of use, powerful functionality, scalability, high security, and free open source. It can save time, improve website quality, enhance collaboration and reduce development costs, and is widely used in various websites such as news websites, blogs, corporate websites, e-commerce websites and community forums.

Title: WeChat Login Integration Guide: PHPCMS in Action In today’s Internet era, social login has become one of the essential functions of a website. As one of the most popular social platforms in China, WeChat’s login function is also used by more and more websites. This article will introduce how to integrate the WeChat login function in the PHPCMS website and provide specific code examples. Step 1: Register a WeChat Open Platform Account First, we need to register a developer account on the WeChat Open Platform and apply for the corresponding development permissions. Log in [WeChat open platform]

Practical tips for integrating PHPcms with other systems With the continuous development of Internet technology, the field of website development has become more diverse and complex. In actual projects, we often face situations where different systems need to be integrated, which requires us to have certain skills and experience to solve these problems. This article will introduce some practical tips and specific code examples for the integration of the PHPcms system with other systems to help developers better cope with challenges. 1. Basic Principles of Integration When performing system integration, it is first necessary to

The mechanisms for integrating the PHP framework with the CMS include: hooks and events, which allow the CMS to hook into the framework's life cycle events. Bridges and adapters provide standardized methods for calling CMS functions. Self-contained code that enables the CMS to run independently of the framework. Practical example: It is possible to integrate a WordPress blog into the Laravel framework by creating custom routes, controllers and importing database dumps.

PHPCMS is a free and open source content management system (CMS) that features: open source, modularity, flexibility, user-friendliness and community support. It can be used to create various types of websites, including corporate websites, e-commerce websites, blogs, and community forums. Technical requirements include: PHP 5.6 or higher, MySQL, MariaDB or PostgreSQL database, and Apache or Nginx web server.

PHPCMS user name security setting strategy revealed In website development, user account security has always been an aspect that developers attach great importance to. The security settings of the username are also crucial, because the username is not only the user's login credentials, but may also expose the user's personal information and even cause security risks. This article will reveal the username security setting strategy in PHPCMS and give specific code examples for developers to refer to. 1. Prevent common usernames. In order to improve the security of usernames, developers should prevent users from using excessive

Build a PHP cloud transcoding CMS system to implement video transcoding services. With the rapid development of online videos, video transcoding services have become more and more important. In order to meet users' needs for video transcoding, building a PHP cloud transcoding CMS system is a good choice. In this article, we will introduce how to build a simple PHP cloud transcoding CMS system and provide specific code examples. First, we need to prepare a basic PHP development environment. Make sure you have PHP and MySQL installed and have a web server such as Apa
