From d2bd117486558f9be81b9103bd56ccfeafecf27f Mon Sep 17 00:00:00 2001 From: phpnut Date: Thu, 23 Feb 2006 08:24:23 +0000 Subject: [PATCH] Merging fixes and enhancements into trunk. Revision: [2098] Removed check for database class to load model classes from the models directory. Fixed missing views not being found. Revision: [2097] Fixed the WWW_ROOT setting Revision: [2096] Changed the way Sessions component is added to the components array Revision: [2095] Moved the WWW_ROOT define. Revision: [2094] Components/Helpers etc. in AppController are now automatically added to all controllers git-svn-id: https://svn.cakephp.org/repo/trunk/cake@2099 3807eeeb-6ff5-0310-8944-8be069107fe0 --- VERSION.txt | 2 +- app/webroot/index.php | 3 +- cake/bootstrap.php | 2 +- cake/config/paths.php | 5 - .../controller/components/request_handler.php | 8 + cake/libs/controller/controller.php | 19 +- cake/libs/view/view.php | 227 +++++++++--------- 7 files changed, 138 insertions(+), 128 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 0ea5e0ae4..ab04a7c0d 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -6,4 +6,4 @@ // +---------------------------------------------------------------------------------------------------+ // /////////////////////////////////////////////////////////////////////////////////////////////////////////// -0.10.8.2093 \ No newline at end of file +0.10.8.2099 \ No newline at end of file diff --git a/app/webroot/index.php b/app/webroot/index.php index beb5c10dd..e471da78f 100644 --- a/app/webroot/index.php +++ b/app/webroot/index.php @@ -70,8 +70,9 @@ if (!defined('WEBROOT_DIR')) define ('WEBROOT_DIR', basename(dirname(__FILE__))); } -ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS); +define('WWW_ROOT', dirname(__FILE__)); +ini_set('include_path',ini_get('include_path').PATH_SEPARATOR.CAKE_CORE_INCLUDE_PATH.PATH_SEPARATOR.ROOT.DS.APP_DIR.DS); require 'cake'.DS.'bootstrap.php'; diff --git a/cake/bootstrap.php b/cake/bootstrap.php index 521bd43cf..f02631f01 100644 --- a/cake/bootstrap.php +++ b/cake/bootstrap.php @@ -109,7 +109,7 @@ require LIBS.'model'.DS.'connection_manager.php'; config('database'); -if (class_exists('DATABASE_CONFIG') && !class_exists('AppModel')) +if (!class_exists('AppModel')) { require LIBS.'model'.DS.'model.php'; loadModels(); diff --git a/cake/config/paths.php b/cake/config/paths.php index 8c633e804..07cf50649 100644 --- a/cake/config/paths.php +++ b/cake/config/paths.php @@ -116,11 +116,6 @@ define ('LOGS', ROOT.DS.'logs'.DS); */ define ('MODULES', ROOT.DS.'modules'.DS); -/** - * Path to the public directory. - */ -define ('WWW_ROOT', APP.WEBROOT_DIR.DS); - /** * Path to the public directory. */ diff --git a/cake/libs/controller/components/request_handler.php b/cake/libs/controller/components/request_handler.php index 317527d48..c966c580b 100644 --- a/cake/libs/controller/components/request_handler.php +++ b/cake/libs/controller/components/request_handler.php @@ -49,6 +49,8 @@ class RequestHandlerComponent extends Object var $ajaxLayout = 'ajax'; + var $disableStartup = false; + /** * Startup @@ -59,6 +61,7 @@ class RequestHandlerComponent extends Object function startup(&$controller) { $this->setAjax($controller); + } /** @@ -69,6 +72,11 @@ class RequestHandlerComponent extends Object */ function setAjax(&$controller) { + if ($this->disableStartup) + { + return; + } + if ($this->isAjax()) { $controller->layout = $this->ajaxLayout; diff --git a/cake/libs/controller/controller.php b/cake/libs/controller/controller.php index befefe95b..43cbb2d2e 100644 --- a/cake/libs/controller/controller.php +++ b/cake/libs/controller/controller.php @@ -211,15 +211,30 @@ class Controller extends Object $this->viewPath = Inflector::underscore($this->name); $this->modelClass = Inflector::singularize($this->name); $this->modelKey = Inflector::underscore($this->modelClass); + if(!defined('AUTO_SESSION') || AUTO_SESSION == true) { - array_push($this->components, 'Session'); + $this->components[] = 'Session'; + } + + if (is_subclass_of($this, 'AppController')) + { + $appVars = get_class_vars('AppController'); + foreach(array('components', 'helpers', 'uses') as $var) + { + if (isset($appVars[$var]) && !empty($appVars[$var])) + { + $diff = array_diff($appVars[$var], $this->{$var}); + $this->{$var} = array_merge($this->{$var}, $diff); + } + } } parent::__construct(); } /** - * Enter description here... + * Loads and instantiates classes required by this controller, + * including components and models * */ function constructClasses() diff --git a/cake/libs/view/view.php b/cake/libs/view/view.php index 303c931a5..cd217a4cf 100644 --- a/cake/libs/view/view.php +++ b/cake/libs/view/view.php @@ -250,140 +250,131 @@ class View extends Object function render($action=null, $layout=null, $file=null) { if (isset($this->hasRendered) && $this->hasRendered) - { - return true; - } - else - { - $this->hasRendered = false; - } + { + return true; + } + else + { + $this->hasRendered = false; + } - if (!$action) - { - $action = $this->action; - } - if ($layout) - { - $this->setLayout($layout); - } + if (!$action) + { + $action = $this->action; + } - if ($file) - { - $viewFileName = $file; - } - else - { - $viewFileName = $this->_getViewFileName($action); - } + if ($layout) + { + $this->setLayout($layout); + } - if(!is_null($this->plugin) && is_null($file)) - { - return $this->pluginView($action, $layout); - } + if ($file) + { + $viewFileName = $file; + } + else + { + $viewFileName = $this->_getViewFileName($action); + } - if (!is_file($viewFileName) && !$viewFileName = fileExistsInPath($viewFileName)) - { - if (strtolower(get_class($this)) == 'template') - { - return array('action' => $action, 'layout' => $layout, 'viewFn' => $viewFileName); - } + if(!is_null($this->plugin) && is_null($file)) + { + return $this->pluginView($action, $layout); + } -// check to see if the missing view is due to a custom missingAction - if (strpos($action, 'missingAction') !== false) - { - $errorAction = 'missingAction'; - } - else - { - $errorAction = 'missingView'; - } + if (!is_file($viewFileName) && !$viewFileName = fileExistsInPath($viewFileName) && !$viewFileName === DS) + { -// check for controller-level view handler - foreach(array($this->name, 'errors') as $viewDir) - { - $errorAction =Inflector::underscore($errorAction); - if(file_exists(VIEWS.$viewDir.DS.$errorAction.$this->ext)) - { - $missingViewFileName = VIEWS.$viewDir.DS.$errorAction.$this->ext; - } - elseif($missingViewFileName = fileExistsInPath(LIBS.'view'.DS.'templates'.DS.$viewDir.DS.$errorAction.'.thtml')) - { - } - else - { - $missingViewFileName = false; - } - - - $missingViewExists = is_file($missingViewFileName); - if ($missingViewExists) + if (strpos($action, 'missingAction') !== false) { - break; - } - } - - if (strpos($action, 'missingView') === false) - { - return $this->cakeError('missingView', - array(array('className' => $this->controller->name, - 'action' => $action, - 'file' => $viewFileName))); - - $isFatal = isset($this->isFatal) ? $this->isFatal : false; - if (!$isFatal) - { - $viewFileName = $missingViewFileName; - } - } - else - { - $missingViewExists = false; - } - - if (!$missingViewExists || $isFatal) - { -// app/view/errors/missing_view.thtml view is missing! - if (DEBUG) - { - trigger_error(sprintf(__("No template file for view %s (expected %s), create it first'"), $action, $viewFileName), E_USER_ERROR); + $errorAction = 'missingAction'; } else { - $this->error('404', 'Not found', sprintf("The requested address %s was not found on this server.", '', "missing view \"{$action}\"")); + $errorAction = 'missingView'; } - die(); - } - } - - if ($viewFileName && !$this->hasRendered) - { - if(substr($viewFileName, -5) === 'thtml') - { - $out = View::_render($viewFileName, $this->_viewVars, 0); - } - else - { - $out = $this->_render($viewFileName, $this->_viewVars, 0); - } - if ($out !== false) - { - if ($this->layout && $this->autoLayout) + foreach(array($this->name, 'errors') as $viewDir) { - $out = $this->renderLayout($out); + $errorAction =Inflector::underscore($errorAction); + if(file_exists(VIEWS.$viewDir.DS.$errorAction.$this->ext)) + { + $missingViewFileName = VIEWS.$viewDir.DS.$errorAction.$this->ext; + } + elseif($missingViewFileName = fileExistsInPath(LIBS.'view'.DS.'templates'.DS.$viewDir.DS.$errorAction.'.thtml')) + { + + } + else + { + $missingViewFileName = false; + } + + $missingViewExists = is_file($missingViewFileName); + if ($missingViewExists) + { + break; + } } - print $out; - $this->hasRendered = true; - } - else - { - $out = $this->_render($viewFileName, $this->_viewVars, false); - trigger_error(sprintf(__("Error in view %s, got:
%s
"), $viewFileName, $out), E_USER_ERROR); - } + if (strpos($action, 'missingView') === false) + { + return $this->cakeError('missingView', + array(array('className' => $this->controller->name, + 'action' => $action, + 'file' => $viewFileName))); - return true; - } + $isFatal = isset($this->isFatal) ? $this->isFatal : false; + if (!$isFatal) + { + $viewFileName = $missingViewFileName; + } + } + else + { + $missingViewExists = false; + } + + if (!$missingViewExists || $isFatal) + { + if (DEBUG) + { + trigger_error(sprintf(__("No template file for view %s (expected %s), create it first'"), $action, $viewFileName), E_USER_ERROR); + } + else + { + $this->error('404', 'Not found', sprintf("The requested address %s was not found on this server.", '', "missing view \"{$action}\"")); + } + die(); + } + } + + if ($viewFileName && !$this->hasRendered) + { + if(substr($viewFileName, -5) === 'thtml') + { + $out = View::_render($viewFileName, $this->_viewVars, 0); + } + else + { + $out = $this->_render($viewFileName, $this->_viewVars, 0); + } + if ($out !== false) + { + if ($this->layout && $this->autoLayout) + { + $out = $this->renderLayout($out); + } + print $out; + $this->hasRendered = true; + } + else + { + $out = $this->_render($viewFileName, $this->_viewVars, false); + trigger_error(sprintf(__("Error in view %s, got:
%s
"), $viewFileName, $out), E_USER_ERROR); + } + return true; + } } /**