Analysis of the core class of CI frame extended system _php Example

Source: Internet
Author: User
Tags abstract goto codeigniter zend framework

In this paper, we illustrate the method of CI framework extending system core class. Share to everyone for your reference, specific as follows:

First of all, your system extension class is placed under the Application/core, the system core class is Ci_controller, so you can not start with ci_, you need to open application/config/config.php modify:

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

The prefix for you!

Some common modules can unload their core classes inside!

These days I read dilicms (lightweight background architecture), such as his background extension class:

<?php if (! defined (' BasePath ')) exit (' No Direct script access allowed '); Abstract class Admin_controller extends Ci_controller {/** * _admin * Save the information for the current logged-on user * @var Object * @access P
  Ublic **/Public $_admin = NULL;
    /** * constructor * @access public * @return void */Public function __construct () {parent::__construct ();
    $this->load->library (' Session ');
    $this->settings->load (' backend ');
    $this->load->switch_theme (Setting (' Backend_theme '));
    $this->_check_login ();
    $this->load->library (' ACL ');
  $this->load->library (' Plugin_manager '); /** * Check whether the user is logged in * * @access protected * @return void/protected function _check_login () {if (! $th Is->session->userdata (' uid ')) {redirect (' Backend_access_point ').
    '/login '); else {$this->_admin = $this->user_mdl->get_full_user_by_username ($this->session->userdata (
 ' uid '), ' uid ');     if ($this->_admin->status!= 1) {$this->session->set_flashdata (' Error ', "This account has been frozen, please contact admin!")
        ); Redirect (setting (' Backend_access_point ').
      '/login '); }}/** * Load View * * @access protected * @param string * @param array * @return void/protected F
    Unction _template ($template, $data = Array ()) {$data [' tpl '] = $template;
  $this->load->view (' Sys_entry ', $data); /** * Check Permissions * @access protected * @param string * @return void/protected function _check_permit ($acti On = ', $folder = ') {if (! $this->acl->permit ($action, $folder)) {$this->_message (' Sorry, you didn't visit Ask for permission here!
    ', ', FALSE); }/** * Information hint * * @access public * @param String * @param string * @param bool * @param string * @retu RN void */Public Function _message ($msg, $goto = ', $auto = TRUE, $fix = ') {if ($goto = = ') {$go to = Isset ($_server[' http_referer ')? $_server[' Http_referer ']: Site_url ();  
    else {$goto = Strpos ($goto, ' http ')!== false $goto: Backend_url ($goto);
    $goto. = $fix;
    $this->_template (' Sys_message ', Array (' msg ' => $msg, ' goto ' => $goto, ' auto ' => $auto));
    echo $this->output->get_output ();
  Exit ();

 }
}

It put some public information into the verification, landing, jump placed in the admin_controller inside, so I write the front desk is also such operations, extended Font_controller:

Abstract class Font_controller extends ci_controller{public
 function __construct () {
  parent::__construct ();
 }
 //Foreground load View method public
 function _template ($template, $data = Array ()) {
  $data [' nav '] = $this->get_nav ();
  $data [' tpl '] = $template;
  $this->load->view (' Default ', $data);
 }
 Common navigation Information public
 function Get_nav () {
 }
 //Common link Information public
 function Get_friendlink () {
 }
}

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

More interested in CodeIgniter related content readers can view the site topics: "CodeIgniter Introductory Course", "CI (CodeIgniter) Framework Advanced Course", "PHP Excellent Development Framework Summary", "thinkphp Introductory Course", " Thinkphp Common Methods Summary, "Zend Framework Introduction Course", "PHP object-oriented Programming Introduction Course", "Php+mysql Database operation Introduction Tutorial" and "PHP common database Operation Skills Summary"

I hope this article will help you with the PHP program design based on CodeIgniter framework.

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.