Home Backend Development PHP Tutorial Analysis on methods of CI framework extending system core classes

Analysis on methods of CI framework extending system core classes

Jun 14, 2018 pm 01:43 PM
ci framework Expand

This article mainly introduces the method of CI framework to extend system core classes, and analyzes the steps and related operating techniques of CI framework to extend system core classes in the form of examples. Friends in need can refer to this article

The example describes how the CI framework extends the core classes of the system. Share it with everyone for your reference. The details are as follows:

First of all, your system extension class is placed under application/core. Originally, the core class of the system is CI_Controller, so you cannot start with CI_. You need to open application /config/config.php Modify:

1

$config['subclass_prefix'] = 'MY_';

Copy after login

is your prefix!

Some public modules can be uninstalled in their own core classes Got it!

I have read Dilicms (lightweight background architecture) these days. For example, his background extension class is like this:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

98

99

100

101

102

<?php if ( ! defined(&#39;BASEPATH&#39;)) exit(&#39;No direct script access allowed&#39;);

abstract class Admin_Controller extends CI_Controller

{

  /**

  * _admin

  * 保存当前登录用户的信息

  *

  * @var object

  * @access public

  **/

  public $_admin = NULL;

  /**

  * 构造函数

  *

  * @access public

  * @return void

  */

  public function __construct()

  {

    parent::__construct();

    $this->load->library(&#39;session&#39;);

    $this->settings->load(&#39;backend&#39;);

    $this->load->switch_theme(setting(&#39;backend_theme&#39;));

    $this->_check_login();

    $this->load->library(&#39;acl&#39;);

    $this->load->library(&#39;plugin_manager&#39;);

  }

 /**

  * 检查用户是否登录

  *

  * @access protected

  * @return void

  */

  protected function _check_login()

  {

    if ( ! $this->session->userdata(&#39;uid&#39;))

    {

      redirect(setting(&#39;backend_access_point&#39;) . &#39;/login&#39;);

    }

    else

    {

      $this->_admin = $this->user_mdl->get_full_user_by_username($this->session->userdata(&#39;uid&#39;), &#39;uid&#39;);

      if ($this->_admin->status != 1)

      {

        $this->session->set_flashdata(&#39;error&#39;, "此帐号已被冻结,请联系管理员!");

        redirect(setting(&#39;backend_access_point&#39;) . &#39;/login&#39;);

      }

    }

  }

 /**

  * 加载视图

  *

  * @access protected

  * @param string

  * @param array

  * @return void

  */

  protected function _template($template, $data = array())

  {

    $data[&#39;tpl&#39;] = $template;

    $this->load->view(&#39;sys_entry&#39;, $data);

  }

 /**

  * 检查权限

  *

  * @access protected

  * @param string

  * @return void

  */

  protected function _check_permit($action = &#39;&#39;, $folder = &#39;&#39;)

  {

    if ( ! $this->acl->permit($action, $folder))

    {

      $this->_message(&#39;对不起,你没有访问这里的权限!&#39;, &#39;&#39;, FALSE);

    }

  }

 /**

  * 信息提示

  *

  * @access public

  * @param string

  * @param string

  * @param bool

  * @param string

  * @return void

  */

  public function _message($msg, $goto = &#39;&#39;, $auto = TRUE, $fix = &#39;&#39;)

  {

    if($goto == &#39;&#39;)

    {

      $goto = isset($_SERVER[&#39;HTTP_REFERER&#39;]) ? $_SERVER[&#39;HTTP_REFERER&#39;] : site_url();

    }

    else

    {

      $goto = strpos($goto, &#39;http&#39;) !== false ? $goto : backend_url($goto); 

    }

    $goto .= $fix;

    $this->_template(&#39;sys_message&#39;, array(&#39;msg&#39; => $msg, &#39;goto&#39; => $goto, &#39;auto&#39; => $auto));

    echo $this->output->get_output();

    exit();

  }

}

Copy after login

It puts some public information into verification, login, and jump in Admin_Controller, so I did the same when writing the front desk and extended Font_Controller:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

abstract class Font_Controller extends CI_Controller{

 public function __construct() {

  parent::__construct();

 }

 //前台加载视图方法

 public function _template($template, $data = array()){

  $data[&#39;nav&#39;] = $this->get_nav();

  $data[&#39;tpl&#39;] = $template;

  $this->load->view(&#39;default&#39;,$data);

 }

 //公共导航信息

 public function get_nav(){

 }

 //公共友情链接信息

 public function get_friendlink(){

 }

}

Copy after login

Tips, some frequently used tools and functions can be placed in helper!

The above is the entire content of this article. I hope it will be helpful to everyone's study. For more related content, please pay attention to the PHP Chinese website!

Related recommendations:

About the method of loading views in CI framework views

Simple analysis of MVC in CI framework

The above is the detailed content of Analysis on methods of CI framework extending system core classes. For more information, please follow other related articles on the PHP Chinese website!

Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

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

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

From start to finish: How to use php extension cURL to make HTTP requests From start to finish: How to use php extension cURL to make HTTP requests Jul 29, 2023 pm 05:07 PM

From start to finish: How to use php extension cURL for HTTP requests Introduction: In web development, it is often necessary to communicate with third-party APIs or other remote servers. Using cURL to make HTTP requests is a common and powerful way. This article will introduce how to use PHP to extend cURL to perform HTTP requests, and provide some practical code examples. 1. Preparation First, make sure that php has the cURL extension installed. You can execute php-m|grepcurl on the command line to check

How to use PHP's SNMP extension? How to use PHP's SNMP extension? Jun 02, 2023 am 10:22 AM

The SNMP extension for PHP is an extension that enables PHP to communicate with network devices through the SNMP protocol. Using this extension, you can easily obtain and modify the configuration information of network devices, such as CPU, memory, network interface and other information of routers, switches, etc. You can also perform control operations such as switching device ports. This article will introduce the basic knowledge of the SNMP protocol, how to install the SNMP extension of PHP, and how to use the SNMP extension in PHP to monitor and control network devices. 1. SN

Extensions and third-party modules for PHP functions Extensions and third-party modules for PHP functions Apr 13, 2024 pm 02:12 PM

To extend PHP function functionality, you can use extensions and third-party modules. Extensions provide additional functions and classes that can be installed and enabled through the pecl package manager. Third-party modules provide specific functionality and can be installed through the Composer package manager. Practical examples include using extensions to parse complex JSON data and using modules to validate data.

How to use CI framework in php? How to use CI framework in php? Jun 01, 2023 am 08:48 AM

With the development of network technology, PHP has become one of the important tools for Web development. One of the popular PHP frameworks - CodeIgniter (hereinafter referred to as CI) has also received more and more attention and use. Today, we will take a look at how to use the CI framework. 1. Install the CI framework First, we need to download the CI framework and install it. Download the latest version of the CI framework compressed package from CI's official website (https://codeigniter.com/). After the download is complete, unzip

How to install mbstring extension under CENTOS7? How to install mbstring extension under CENTOS7? Jan 06, 2024 pm 09:59 PM

1.UncaughtError:Calltoundefinedfunctionmb_strlen(); When the above error occurs, it means that we have not installed the mbstring extension; 2. Enter the PHP installation directory cd/temp001/php-7.1.0/ext/mbstring 3. Start phpize(/usr/local/bin /phpize or /usr/local/php7-abel001/bin/phpize) command to install php extension 4../configure--with-php-config=/usr/local/php7-abel

How to use PHP's ZipArchive extension? How to use PHP's ZipArchive extension? Jun 02, 2023 am 08:13 AM

PHP is a popular server-side language that can be used to develop web applications and process files. The ZipArchive extension for PHP is a powerful tool for manipulating zip files in PHP. In this article, we’ll cover how to use PHP’s ZipArchive extension to create, read, and modify zip files. 1. Install the ZipArchive extension. Before using the ZipArchive extension, you need to ensure that the extension has been installed. The installation method is as follows: 1. Install

How to use PHP's POSIX extension? How to use PHP's POSIX extension? Jun 03, 2023 am 08:01 AM

The POSIX extensions for PHP are a set of functions and constants that allow PHP to interact with POSIX-compliant operating systems. POSIX (PortableOperatingSystemInterface) is a set of operating system interface standards designed to allow software developers to write applications that can run on various UNIX or UNIX-like operating systems. This article will introduce how to use POSIX extensions for PHP, including installation and use. 1. Install the POSIX extension of PHP in

How to use the Aurora Push extension to implement batch message push function in PHP applications How to use the Aurora Push extension to implement batch message push function in PHP applications Jul 25, 2023 pm 08:07 PM

How to use the Aurora Push extension to implement batch message push function in PHP applications. In the development of mobile applications, message push is a very important function. Jiguang Push is a commonly used message push service that provides rich functions and interfaces. This article will introduce how to use the Aurora Push extension to implement batch message push functionality in PHP applications. Step 1: Register a Jiguang Push account and obtain an API key. First, we need to register on the Jiguang Push official website (https://www.jiguang.cn/push)

See all articles