PHP source code mvc initialization class has a setUrl method that cannot be run

Source: Internet
Author: User
& Amp; lt ;? PhpPrivilegeAction. class. php {code...} & amp; lt ;? Phpindexphp {code ...}

// PrivilegeAction. class. php

// Determine whether a constant is defined. If not defined, it means that it is not the index. phpif (! Defined ('access') exit; // class initialization class Application {// 1. initialize the character set private static function setHeader () {echo _ METHOD __."
"; Header ('content-type: text/html; charset = UTF-8 ');} // 2. initialize the system constant private static function setConst () {echo _ METHOD __."
"; // Set the ROOT directory constant define ('root _ dir', str_replace ('/core','', str_replace ('\\','/', __dir _); // define other directories define ('Core _ dir', ROOT_DIR. '/core'); define ('Action _ dir', ROOT_DIR. '/Action'); define ('conf _ dir', ROOT_DIR. '/conf'); define ('model _ dir', ROOT_DIR. '/model'); define ('view _ dir', ROOT_DIR. '/view'); define ('pub _ dir', ROOT_DIR. '/public');} // 3. error message private static function setErrors () {echo _ METHOD __."
"; // In the development environment, an error is displayed. All levels of errors are displayed. // in the production environment, no errors are displayed. All levels of errors are hidden. (The system must handle fault tolerance) @ ini_set ('error _ report', 1); @ ini_set ('display _ errors ', 1);} // 4. automatically load // 4.1 load the Controller class public static function loadAction ($ class) {echo _ METHOD __."
"; // Determine if (is_file (ACTION_DIR. "/$ class. class. php ") {include_once ACTION_DIR. "/$ class. class. php ";}}// 4.2 load the core class public static function loadCore ($ class) {echo _ METHOD __."
"; // Determine if (is_file (CORE_DIR. "/$ class. class. php ") {include_once CORE_DIR. "/$ class. class. php ";}}// 4.3 load model class public static function loadModel ($ class) {echo _ METHOD __."
"; // Determine if (is_file (MODEL_DIR. "/$ class. class. php ") {include_once MODEL_DIR. "/$ class. class. php ";}}// register all automatic loading methods to the automatic loading mechanism. private static function setAutoload () {echo _ METHOD __."
"; Spl_autoload_register (array ('application', 'loadcore'); spl_autoload_register (array ('application', 'loadaction ')); // The system will determine whether the currently provided parameter is a function (string) or an array // if it is an array: 1. find the first parameter of the array and judge this parameter. If the parameter is not an object, the system will think that the string is a class name. Therefore, when you splice the string for access, the second parameter // Application: loadCore (); spl_autoload_register (array ('application', 'loadmodel') will be accessed using the range resolution operator;} // 5. enable the session mechanism private static function setSession () {echo _ METHOD __."
"; // Enable session @ session_start () ;}// 6. Load the configuration file private static function setConfig () {echo _ METHOD __."
"; $ GLOBALS ['config'] = include_once CONF_DIR. '/config. php ';} // 7. URL initialization private static function setUrl () {echo _ METHOD __."
"; // GET the user's url information (data submitted in GET mode) // module: the requested module (Controller) $ module = isset ($ _ REQUEST ['module'])? $ _ REQUEST ['module']: 'privilege'; // action: REQUEST Method $ action = isset ($ _ REQUEST ['action'])? $ _ REQUEST ['action']: 'login ';
// Process the string // 1. convert all to lower case $ module = strtolower ($ module); $ action = strtolower ($ action); // 2. the first letter of the class is capitalized, and $ module = ucfirst ($ module) is not required for the method ); // define the obtained data as constants for subsequent methods. define ('module', $ MODULE); define ('action ', $ action);} // 8. permission verification private static function setPrivilege () {echo _ METHOD __."
"; // Release some controller methods that do not require verification if (! (MODULE = 'privilege' & (ACTION = 'login' | ACTION = 'signin' | ACTION = 'captcha '))) {// verify if (! Isset ($ _ SESSION ['user']) {// the user does not have a logon header ('location: index. php ') ;}}// 9. distribute private static function setDispatch () {echo _ METHOD __; // find the corresponding controller class, instantiate it, and then call the corresponding METHOD to $ module = MODULE. 'action'; // get the Controller name $ module = new $ module (); // create a controller object $ Action = action; $ module-> $ ACTION (); // call the method in the Controller}
// Initialization method public static function run () {// initialize the project // 1. initialize the character set self: setHeader (); // 2. initialize the system constant self: setConst (); // 3. error message self: setErrors (); // 4. automatically load self: setAutoload (); // 5. enable session self: setSession (); // 6. configuration File self: setConfig (); // 7. URL initialization self: setUrl (); // 8. permission verification self: setPrivilege (); // 9. distribute self: setDispatch ();}}

// Indexphp

// Define a constant for judgment of other files // The constant define ('access', 'Acc ') of the entry file; // load the initialization class Application. class. phpinclude_once 'core/Application. class. php '; // call the system initialization method // call the static method of the Application class Application: run ();

Reply content:

// PrivilegeAction. class. php

// Determine whether a constant is defined. If not defined, it means that it is not the index. phpif (! Defined ('access') exit; // class initialization class Application {// 1. initialize the character set private static function setHeader () {echo _ METHOD __."
"; Header ('content-type: text/html; charset = UTF-8 ');} // 2. initialize the system constant private static function setConst () {echo _ METHOD __."
"; // Set the ROOT directory constant define ('root _ dir', str_replace ('/core','', str_replace ('\\','/', __dir _); // define other directories define ('Core _ dir', ROOT_DIR. '/core'); define ('Action _ dir', ROOT_DIR. '/Action'); define ('conf _ dir', ROOT_DIR. '/conf'); define ('model _ dir', ROOT_DIR. '/model'); define ('view _ dir', ROOT_DIR. '/view'); define ('pub _ dir', ROOT_DIR. '/public');} // 3. error message private static function setErrors () {echo _ METHOD __."
"; // In the development environment, an error is displayed. All levels of errors are displayed. // in the production environment, no errors are displayed. All levels of errors are hidden. (The system must handle fault tolerance) @ ini_set ('error _ report', 1); @ ini_set ('display _ errors ', 1);} // 4. automatically load // 4.1 load the Controller class public static function loadAction ($ class) {echo _ METHOD __."
"; // Determine if (is_file (ACTION_DIR. "/$ class. class. php ") {include_once ACTION_DIR. "/$ class. class. php ";}}// 4.2 load the core class public static function loadCore ($ class) {echo _ METHOD __."
"; // Determine if (is_file (CORE_DIR. "/$ class. class. php ") {include_once CORE_DIR. "/$ class. class. php ";}}// 4.3 load model class public static function loadModel ($ class) {echo _ METHOD __."
"; // Determine if (is_file (MODEL_DIR. "/$ class. class. php ") {include_once MODEL_DIR. "/$ class. class. php ";}}// register all automatic loading methods to the automatic loading mechanism. private static function setAutoload () {echo _ METHOD __."
"; Spl_autoload_register (array ('application', 'loadcore'); spl_autoload_register (array ('application', 'loadaction ')); // The system will determine whether the currently provided parameter is a function (string) or an array // if it is an array: 1. find the first parameter of the array and judge this parameter. If the parameter is not an object, the system will think that the string is a class name. Therefore, when you splice the string for access, the second parameter // Application: loadCore (); spl_autoload_register (array ('application', 'loadmodel') will be accessed using the range resolution operator;} // 5. enable the session mechanism private static function setSession () {echo _ METHOD __."
"; // Enable session @ session_start () ;}// 6. Load the configuration file private static function setConfig () {echo _ METHOD __."
"; $ GLOBALS ['config'] = include_once CONF_DIR. '/config. php ';} // 7. URL initialization private static function setUrl () {echo _ METHOD __."
"; // GET the user's url information (data submitted in GET mode) // module: the requested module (Controller) $ module = isset ($ _ REQUEST ['module'])? $ _ REQUEST ['module']: 'privilege'; // action: REQUEST Method $ action = isset ($ _ REQUEST ['action'])? $ _ REQUEST ['action']: 'login ';
// Process the string // 1. convert all to lower case $ module = strtolower ($ module); $ action = strtolower ($ action); // 2. the first letter of the class is capitalized, and $ module = ucfirst ($ module) is not required for the method ); // define the obtained data as constants for subsequent methods. define ('module', $ MODULE); define ('action ', $ action);} // 8. permission verification private static function setPrivilege () {echo _ METHOD __."
"; // Release some controller methods that do not require verification if (! (MODULE = 'privilege' & (ACTION = 'login' | ACTION = 'signin' | ACTION = 'captcha '))) {// verify if (! Isset ($ _ SESSION ['user']) {// the user does not have a logon header ('location: index. php ') ;}}// 9. distribute private static function setDispatch () {echo _ METHOD __; // find the corresponding controller class, instantiate it, and then call the corresponding METHOD to $ module = MODULE. 'action'; // get the Controller name $ module = new $ module (); // create a controller object $ Action = action; $ module-> $ ACTION (); // call the method in the Controller}
// Initialization method public static function run () {// initialize the project // 1. initialize the character set self: setHeader (); // 2. initialize the system constant self: setConst (); // 3. error message self: setErrors (); // 4. automatically load self: setAutoload (); // 5. enable session self: setSession (); // 6. configuration File self: setConfig (); // 7. URL initialization self: setUrl (); // 8. permission verification self: setPrivilege (); // 9. distribute self: setDispatch ();}}

// Indexphp

// Define a constant for judgment of other files // The constant define ('access', 'Acc ') of the entry file; // load the initialization class Application. class. phpinclude_once 'core/Application. class. php '; // call the system initialization method // call the static method of the Application class Application: run ();

This should not besetUrlNot running, but in the previoussetConfig.
ChecksetConfigIn$GLOBALS['config'] = include_once CONF_DIR . '/config.php';
Lookconfig.phpIs the content in.

The configuration file is incorrect.

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.