@@ -102,14 +102,20 @@ function Dispatcher:dispatch()
102102 self .view = self .application :lpcall (new_view , self .application .config .view )
103103 self :_runPlugins (' dispatchLoopStartup' )
104104 self :_runPlugins (' preDispatch' )
105- -- local matched_controller = self:lpcall(require_controller, self.controller_prefix, self.request.controller_name)
106- local matched_controller_lib = self :lpcall (require_controller , self .controller_prefix , self .request .controller_name )
107- local mt = getmetatable (matched_controller_lib )
108- mt .__index = self .controller
109- local matched_controller = matched_controller_lib ()
110- setmetatable (matched_controller .class , mt )
111- -- setmetatable(matched_controller.class, { __index = self.controller })
112- local c_rs = self :lpcall (call_controller , self , matched_controller , self .request .controller_name , self .request .action_name )
105+ local cls_call = {}
106+ local matched_controller = self :lpcall (require_controller , self .controller_prefix , self .request .controller_name )
107+ if matched_controller .parent ~= nil and type (matched_controller .parent ) == ' table' then
108+ setmetatable (matched_controller .parent , {__index = self .controller })
109+ cls_call = matched_controller ()
110+ elseif matched_controller .__cname ~= nil then
111+ local mt = getmetatable (matched_controller )
112+ mt .__index = self .controller
113+ cls_call = matched_controller ()
114+ setmetatable (cls_call .class , mt )
115+ else
116+ cls_call = setmetatable (matched_controller , { __index = self .controller })
117+ end
118+ local c_rs = self :lpcall (call_controller , self , cls_call , self .request .controller_name , self .request .action_name )
113119 if type (c_rs ) ~= ' string' then
114120 self :errResponse ({ code = 103 , msg = {Rs_Error = self .request .controller_name .. ' /' .. self .request .action_name .. ' must return a String.' }})
115121 end
0 commit comments