From 3eefab1bdbeea9eb92e000088d4b77d21c9e6a25 Mon Sep 17 00:00:00 2001 From: Xuan Sang LE Date: Wed, 22 Aug 2018 19:50:52 +0200 Subject: [PATCH] allow controller to change view layout --- apps/controllers/PostController.lua | 1 + apps/index.ls | 27 --------------------------- apps/silk/BaseController.lua | 4 ++++ apps/silk/Router.lua | 2 +- 4 files changed, 6 insertions(+), 28 deletions(-) delete mode 100644 apps/index.ls diff --git a/apps/controllers/PostController.lua b/apps/controllers/PostController.lua index 334dbf9..ef48e17 100644 --- a/apps/controllers/PostController.lua +++ b/apps/controllers/PostController.lua @@ -18,6 +18,7 @@ function PostController:edit(...) else self.template:set("auth", false) end + self:setLayout("admin") --self:redirect("/category/put/1") return true end diff --git a/apps/index.ls b/apps/index.ls deleted file mode 100644 index ce19292..0000000 --- a/apps/index.ls +++ /dev/null @@ -1,27 +0,0 @@ - - - Application pages - - - -
- ") - v:render() - echo("
") - end - --views.__main__:render() - ?> -
- - \ No newline at end of file diff --git a/apps/silk/BaseController.lua b/apps/silk/BaseController.lua index fe22523..dd1727a 100644 --- a/apps/silk/BaseController.lua +++ b/apps/silk/BaseController.lua @@ -27,6 +27,10 @@ function BaseController:redirect(url) std.header_flush() end +function BaseController:setLayout(name) + self.registry.layout = name +end + function BaseController:setSession(key, value) SESSION[key] = value end diff --git a/apps/silk/Router.lua b/apps/silk/Router.lua index d9c19d2..45bbbe8 100644 --- a/apps/silk/Router.lua +++ b/apps/silk/Router.lua @@ -75,7 +75,7 @@ function Router:delegate() end -- now require the main page to put the view - local fn, e = loadscript(WWW_ROOT..DIR_SEP.."index.ls") + local fn, e = loadscript(VIEW_ROOT..DIR_SEP..self.registry.layout..DIR_SEP.."index.ls") html() if fn then local r,o = pcall(fn, views)