Shopex's app development mechanismShopex's app development mechanism allows us to implement the following features:
1. Build your own database tables.
2. Create your own controller.
3. Add columns to the front and rear tables.
4, replace the system default (custom business process) with your own controller.
5. Add event listeners to make system events call your own code.
Here's a small example to illustrate thisApp Feature Pack Basic Development steps: 1, in the Web site root directory of the/plugins/app directory to create the demo directory, then this file must have a app.demo.php file, this file can be defined as follows:
classApp_demoextendsapp{var $ver= 0.8; var $name= ' Sample program '; var $website= ' http://www.shopex.cn '; var $author= ' [email protected] '; //Optional Functions//define which processes to take over the system, by which class/method to execute//This example indicates that the foreground will redirect all controller requests that access the shopping cart to the Cartidx method of the Democtl object within this package. functionCtl_mapper () {return Array( ' Shop:cart:index ' = ' demo_ctl:cartidx ', ); } //Optional Functions//listening system which events//Here are the available keywords any for all events//This example indicates://listen for order new events, call the Order_new method of the Event_handle class to execute//Listen member new event-& Gt Call the Member_create method of the Event_handle class to execute functionListener () {return Array( ' Trading/order:create ' = ' demo_event_handler:order_new ', ' member/account:register ' ' Demo_event_handler:member_create ', ' any ' = ' demo_event_handler:any ', ); } //Optional function that returns the information needed to build the table//This example is to build two tables, the system will automatically prefix sdb_ functionDbtables () {$tables[' table_2 '] =Array ( ' Columns ' =Array ( ' Controller ' =Array ( ' type ' = ' varchar ', ' required ' =true, ' pkey ' =true, ' editable ' =false, ), ' plugin ' =Array ( ' type ' = ' varchar ', ' required ' =true, ' editable ' =false, ), ), ); $tables[' table_1 '] =Array ( ' Columns ' =Array ( ' Controller ' =Array ( ' type ' = ' varchar ', ' required ' =true, ' pkey ' =true, ' editable ' =false, ), ' plugin ' =Array ( ' type ' = ' varchar ', ' required ' =true, ' editable ' =false, ), ), ); return $tables; } //I admit it's a very wicked design ...//But you have to admit that it can make you omnipotent . functionoutput_modifiers () {return Array( ' Admin:goods/product:index ' = ' demo_modifiers:product_edit ' ); } //Overloaded Installation Method ...//can also be overloaded with://Uninstall---uninstall//Enable, program start//disable, program off functionInstall () {//don't forget to call the parent class's install returnParent::Install (); } }
2, in order to prevent naming conflicts, please use the name of your own package as the prefix of the class, file Plugins/app/demo/demo_event_ handler.php, here is corresponding to the above app.demo.php definition of the system itself with the method docking, the file code is as follows:
classdemo_event_handler{//This method will be executed automatically when the order is created//here the event is assigned a value of Order:new functionOrder_new ($event _type,$order _data){ ... }//This method will be executed automatically when the member is newly created//This event is assigned a value of Order:new functionMember_create ($event _type,$member _data){ ... }//any event will call this function functionAny$event _type,$event _data){ ... }}
3, for example, with the front shopping cart operation Docking, we can define a file to implement this function, such as file plugins/app/demo/demo_ctl.php, the code is as follows:
require(' app_page.php ');classDemo_ctlextendsapp_page{functionCartidx () {//output Template: cart.html in the Package folder $this-system;//System entry can be invoked $this->db;//You can use the database directly//load the class in the package ... require(dirname(__file__).‘ /demo_my_model_layer.php '); $obj=NewDemo_my_model_layer;$this->output (' view/cart.html '); } }
4, establish a class to redefine the shopping cart page with keyword <{$_BASE_PATH_}> can be located to the URL of the plugin folder, such as we create a template file plugins/app/demo/view/ Cart.html in the file we can use this keywordsuch as outputPlugins/app/demo/images/cart.png.The above code is just a little elaboration of the nextSome of the small features of Shopex's accessibility package, if used well, will feel like a duck in the bag and hopefully the code helps.
"Shopex" app development mechanism