@@ -28,19 +28,21 @@ public function execute($addon = null, $controller = null, $action = null)
2828 $ addon = $ addon ? call_user_func ($ filter , $ addon ) : '' ;
2929 $ controller = $ controller ? call_user_func ($ filter , $ controller ) : 'index ' ;
3030 $ action = $ action ? call_user_func ($ filter , $ action ) : 'index ' ;
31-
31+
3232 Hook::listen ('addon_begin ' , $ request );
33- if (!empty ($ addon ) && !empty ($ controller ) && !empty ($ action ))
34- {
33+ if (!empty ($ addon ) && !empty ($ controller ) && !empty ($ action )) {
3534 $ info = get_addon_info ($ addon );
36- if (!$ info )
37- {
35+ if (!$ info ) {
3836 throw new HttpException (404 , __ ('addon %s not found ' , $ addon ));
3937 }
40- if (!$ info ['state ' ])
41- {
38+ if (!$ info ['state ' ]) {
4239 throw new HttpException (500 , __ ('addon %s is disabled ' , $ addon ));
4340 }
41+ $ dispatch = $ request ->dispatch ();
42+ if (isset ($ dispatch ['var ' ]) && $ dispatch ['var ' ]) {
43+ $ request ->route ($ dispatch ['var ' ]);
44+ }
45+
4446 // 设置当前请求的控制器、操作
4547 $ request ->controller ($ controller )->action ($ action );
4648
@@ -50,37 +52,29 @@ public function execute($addon = null, $controller = null, $action = null)
5052 Hook::listen ('addons_init ' , $ request );
5153
5254 $ class = get_addon_class ($ addon , 'controller ' , $ controller );
53- if (!$ class )
54- {
55+ if (!$ class ) {
5556 throw new HttpException (404 , __ ('addon controller %s not found ' , Loader::parseName ($ controller , 1 )));
5657 }
5758
5859 $ instance = new $ class ($ request );
5960
6061 $ vars = [];
61- if (is_callable ([$ instance , $ action ]))
62- {
62+ if (is_callable ([$ instance , $ action ])) {
6363 // 执行操作方法
6464 $ call = [$ instance , $ action ];
65- }
66- elseif (is_callable ([$ instance , '_empty ' ]))
67- {
65+ } elseif (is_callable ([$ instance , '_empty ' ])) {
6866 // 空操作
6967 $ call = [$ instance , '_empty ' ];
7068 $ vars = [$ action ];
71- }
72- else
73- {
69+ } else {
7470 // 操作不存在
7571 throw new HttpException (404 , __ ('addon action %s not found ' , get_class ($ instance ) . '-> ' . $ action . '() ' ));
7672 }
7773
7874 Hook::listen ('addon_action_begin ' , $ call );
7975
8076 return call_user_func_array ($ call , $ vars );
81- }
82- else
83- {
77+ } else {
8478 abort (500 , lang ('addon can not be empty ' ));
8579 }
8680 }
0 commit comments