framework.class.php
Basic code Display:
1<?PHP2 3 /**4 * Framework initialization function Class5 */6 classFramework {7 /**8 * Entrance
* The static inside is the same as self, which means the current class9 */Ten public Staticfunction Run () { one //declaring Path Constants a Static:: _initpathconst (); - //Determining distribution Parameters - Static:: _initdispatchparam (); the //Current platform-dependent Path Constants - Static:: _initplatformpathconst (); - //register for automatic loading - Static:: _initautoload (); + - //Request Distribution + Static:: _dispatch (); a } at - /** - * Declare path constants - */ - Private Staticfunction _initpathconst () { - //definition of directory base constants inDefine'Root_path', GETCWD ().'/');//getcwd () Get the current directory -Define'Appliction_path', Root_path.'application/'); toDefine'Framework_path', Root_path.'framework/'); +Define'Tool_path', Framework_path.'tool/'); - } the /** * * Initialization of distribution parameters $ */Panax Notoginseng Private Staticfunction _initdispatchparam () { - //Determining distribution Parameters the //Platform +$default _platform =' back'; aDefine'PLATFORM', Isset ($_get['P']) ? $_get['P']: $default _platform); the //Controller Class +$default _controller ='Manage'; -Define'CONTROLLER', Isset ($_get['C']) ? $_get['C']: $default _controller); $ //Action $$default _action ='Index'; -Define'ACTION', Isset ($_get['a']) ? $_get['a']: $default _action); - } the /** - * Declares the current platform path constantWuyi */ the Private Staticfunction _initplatformpathconst () { - //Current platform-dependent Path Constants wuDefine'Current_controller_path', Appliction_path. PLATFORM.'/controller/'); -Define'Current_model_path', Appliction_path. PLATFORM.'/model/'); aboutDefine'Current_view_path', Appliction_path. PLATFORM.'/view/'); $ } - /** - * Automatic Loading method - */ a public Staticfunction Userautoload ($class _name) { + //process the identified (core class in the Framework) first the //class name and class file mapping array -$framework _class_list =Array ( $ //' class name ' = ' + ' class file Address ' the 'Controller'= = Framework_path.'Controller.class.php', the 'Model'= = Framework_path.'Model.class.php', the 'Factory'= = Framework_path.'Factory.class.php', the 'MySQLdb'= = Framework_path.'MySQLDB.class.php', - 'sessiondb'= = Tool_path.'SessionDB.class.php', in ) ; the //determine if the core class the if(isset ($framework _class_list[$class _name])) { about //is the core class the require $framework _class_list[$class _name]; the } the //determine if it can be increased (controller class, model Class) + //controller class, After interception is a character, matching controller -ElseIf (substr ($class _name,-Ten) =='Controller') { the //Controller class, current platform under Controllers directoryBayiRequire Current_controller_path. $class _name.'. class.php'; the } the //Model class, 5 characters after interception, matching model -ElseIf (substr ($class _name,-5) =='Model') { - //model class, Current platform models directory theRequire Current_model_path. $class _name.'. class.php'; the } the } the /** - * Registration Automatic loading the */ the Private Staticfunction _initautoload () { theSpl_autoload_register (array (__class__,'Userautoload'));94 } the /** the * Distribution Request the */98 Private Staticfunction _dispatch () { about //instantiate the Controller class and invoke the action method -$controller _name = Controller.'Controller';101 //instantiation of102$controller =New$controller _name ();//Variable class103 //Invoke method (action Action)104 //piecing together the current method action name string the$action _name = Action.'Action';106$controller, $action _name ();//Variable Method107 }108}
() PHP, Basic Framework class steps