summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNathan Angelacos <nangel@tetrasec.net>2007-11-02 21:01:45 +0000
committerNathan Angelacos <nangel@tetrasec.net>2007-11-02 21:01:45 +0000
commitee27a6341f094e239837c7077e86b0c7f0c306bc (patch)
treea628d69ea056990baf3bb5a2bcfadcb0aa27ae3b
parentd49ec1941b5621f47662c422c0557d62385583bd (diff)
downloadacf-core-ee27a6341f094e239837c7077e86b0c7f0c306bc.tar.bz2
acf-core-ee27a6341f094e239837c7077e86b0c7f0c306bc.tar.xz
mvc.lua - change new to return 3 values, new mvc object,
and a boolean each for the status of loading the named controller and model acf_www-controller.lua - example showing how to cope if the mvc:new returns with a missing model/controller git-svn-id: svn://svn.alpinelinux.org/acf/core/trunk@266 ab2d0c66-481e-0410-8bed-d214d4d58bed
-rw-r--r--app/acf_www-controller.lua16
-rwxr-xr-xwww/cgi-bin/mvc.lua22
2 files changed, 31 insertions, 7 deletions
diff --git a/app/acf_www-controller.lua b/app/acf_www-controller.lua
index 742533a..4f5b755 100644
--- a/app/acf_www-controller.lua
+++ b/app/acf_www-controller.lua
@@ -119,12 +119,24 @@ view_resolver = function(self)
-- with conf, and other "missing" parts pointing back
-- to APP or self
-- ***************************************************
- local m = self:new("alpine-baselayout/hostname")
- local h = m.worker.read(m)
+ local m,worker_loaded,model_loaded = self:new("alpine-baselayout/hostname")
+
+ -- FIXME - this is ugly, but it puts the hostname the expected
+ -- format if the controller doesn't load correctly
+ local h = {}
+
+ -- If the worker and model loaded correctly, then
+ -- use the sub-controller
+ if worker_loaded && model_loaded then
+ h = m.worker.read(m)
+ else
+ h.hostname = { value = "unknown" }
+ end
local pageinfo = { viewfile = viewname,
controller = m.conf.controller,
-- ^^^ see.. m.conf doesnt exist - but it works
+ -- the inheritance means self.conf is used instead
action = self.conf.action,
hostname = h.hostname.value,
prefix = self.conf.prefix,
diff --git a/www/cgi-bin/mvc.lua b/www/cgi-bin/mvc.lua
index 23a71c7..4fe2954 100755
--- a/www/cgi-bin/mvc.lua
+++ b/www/cgi-bin/mvc.lua
@@ -1,5 +1,6 @@
--[[ Basic MVC framework
- Written for Alpine Configuration Framework (ACF) -- see www.alpinelinux.org
+ Written for Alpine Configuration Framework (ACF)
+ see www.alpinelinux.org for more information
Copyright (C) 2007 Nathan Angelacos
Licensed under the terms of GPL2
]]--
@@ -18,13 +19,16 @@ module(..., package.seeall)
]]
new = function (self, modname)
+ local model_loaded = true
+ local worker_loaded = true
local c = {}
c.worker = {}
c.model = {}
-- make defaults if the parent doesn't have them
if self.conf == nil then
- c.conf = { appdir = "", confdir = "", tempdir = "", appname = "" }
+ c.conf = { appdir = "", confdir = "",
+ tempdir = "", appname = "" }
end
-- If no clientdata, then clientdata is a null table
@@ -39,8 +43,16 @@ new = function (self, modname)
-- load the module code here
if (modname) then
- c.worker = self:soft_require( modname .. "-controller") or {}
- c.model = self:soft_require( modname .. "-model" ) or {}
+ c.worker = self:soft_require( modname .. "-controller")
+ if c.worker == nil then
+ c.worker = {}
+ worker_loaded = false
+ end
+ c.model = self:soft_require( modname .. "-model" )
+ if c.model == nil then
+ c.model = {}
+ model_loaded = false
+ end
end
-- The magic that makes all the metatables point in the correct
@@ -81,7 +93,7 @@ new = function (self, modname)
c.worker.mvc.on_load = nil
end
- return c
+ return c worker_loaded model_loaded
end
-- This is a sample front controller/dispatch.