merging fixes into trunk from [857] [858] [859] [860] [861]

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@862 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-09-17 07:56:32 +00:00
parent 1dce095546
commit 29a1ee9043
7 changed files with 107 additions and 91 deletions

View file

@ -0,0 +1,19 @@
<h1>Scaffold Requires a Database Connection</h1>
<p class="error">Missing Database Connection
</p>
<p>
<span class="notice"><strong>Notice:</strong> this error is being rendered by the <code>app/views/errors/missing_database.thtml</code>
view file, a user-customizable error page for handling errors within CakePHP.</span>
</p>
<?if (DEBUG>1):?>
<h2>Controller dump:</h2>
<pre>
<?
unset($this->db);
print_r($this);
?>
</pre>
<?endif?>

View file

@ -1,8 +1,8 @@
<h1>Missing view</h1> <h1>Missing view</h1>
<p class="error">You are seeing this error because the view <em><?=$this->missingView;?></em> <p class="error">You are seeing this error because the view <em><?php echo $this->missingView;?></em>
for action <em><?=$this->params['action'];?></em> for action <em><?php echo $this->params['action'];?></em>
in controller <em><?=Inflector::camelize($this->name);?></em> could not be found. in controller <em><?php echo Inflector::camelize($this->name);?></em> could not be found.
</p> </p>
<p> <p>
@ -11,14 +11,14 @@ view file, a user-customizable error page for handling missing/invalid views dur
</p> </p>
<p> <p>
<strong>Fatal</strong>: Unable to load view file <em><?=$this->missingView;?></em> for <strong>Fatal</strong>: Unable to load view file <em><?php echo $this->missingView;?></em> for
action <em><?=$this->params['controller'];?>::<?=$this->params['action'];?></em> action <em><?php echo $this->params['controller'];?>::<?php echo $this->params['action'];?></em>
</p> </p>
<?if (DEBUG>1):?> <?php if (DEBUG>1):?>
<h2>Controller dump:</h2> <h2>Controller dump:</h2>
<pre> <pre>
<? <?php
unset($this->db); unset($this->db);
print_r($this); print_r($this);
?> ?>

View file

@ -342,23 +342,7 @@ class Controller extends Object
*/ */
function render($action=null, $layout=null, $file=null) function render($action=null, $layout=null, $file=null)
{ {
$view = View::getInstance(); $view =& new View($this);
$view->_viewVars =& $this->_viewVars;
$view->action =& $this->action;
$view->autoLayout =& $this->autoLayout;
$view->autoRender =& $this->autoRender;
$view->base =& $this->base;
$view->helpers =& $this->helpers;
$view->here =& $this->here;
$view->layout =& $this->layout;
$view->models =& $this->models;
$view->name =& $this->name;
$view->pageTitle =& $this->pageTitle;
$view->parent =& $this->parent;
$view->viewPath =& $this->viewPath;
$view->params =& $this->params;
$view->data =& $this->data;
$view->displayFields =& $this->displayFields;
if(!empty($this->models)) if(!empty($this->models))
{ {
@ -405,6 +389,12 @@ class Controller extends Object
$this->render('../errors/missingView'); $this->render('../errors/missingView');
} }
function missingDatabase()
{
//We are simulating action call below, this is not a filename!
$this->render('../errors/missingDatabase');
}
// /** // /**
// * Displays an error page to the user. Uses layouts/error.html to render the page. // * Displays an error page to the user. Uses layouts/error.html to render the page.
// * // *

View file

@ -116,11 +116,9 @@ class Dispatcher extends Object
} }
else else
{ {
// create controller
$controller = new $ctrlClass($this); $controller = new $ctrlClass($this);
} }
// if action is not set, and the default Controller::index() method doesn't exist
if (empty($params['action'])) if (empty($params['action']))
{ {
if (method_exists($controller, 'index')) if (method_exists($controller, 'index'))
@ -129,55 +127,47 @@ class Dispatcher extends Object
} }
else else
{ {
// Check to see if controller is scaffolded
$classVars = get_object_vars($controller);
foreach ($classVars as $name => $value)
{
if($name === 'scaffold')
{
if (empty($params['action']))
{
$params['action'] = 'index';
}
$this->scaffoldView($url, $ctrlClass, $params);
exit;
}
}
$missingAction = true; $missingAction = true;
} }
} }
// if the requested action doesn't exist
if (!method_exists($controller, $params['action'])) if (!method_exists($controller, $params['action']))
{ {
// Check to see if controller is scaffolded
$classVars = get_object_vars($controller);
foreach ($classVars as $name => $value)
{
if($name === 'scaffold')
{
$this->scaffoldView($url, $ctrlClass, $params);
exit;
}
}
$missingAction = true; $missingAction = true;
} }
if ($missingAction)
{
$controller->missingAction = $params['action'];
$params['action'] = 'missingAction';
}
// initialize the controller
$controller->base = $this->base; $controller->base = $this->base;
$controller->here = $this->base.'/'.$url; $controller->here = $this->base.'/'.$url;
$controller->params = $params; $controller->params = $params;
$controller->action = $params['action']; $controller->action = $params['action'];
$controller->data = empty($params['data'])? null: $params['data']; $controller->data = empty($params['data'])? null: $params['data'];
$controller->passed_args = empty($params['pass'])? null: $params['pass']; $controller->passed_args = empty($params['pass'])? null: $params['pass'];
foreach (get_object_vars($controller) as $name => $value)
{
if(($name === 'scaffold' && $missingAction === true)
|| ($name === 'scaffold' && !empty($params['action'])))
{
if (!method_exists($controller, $params['action']))
{
if(empty($params['action']))
{
$params['action'] = 'index';
}
$this->scaffoldView($url, $controller, $params);
exit;
}
}
}
$controller->contructClasses(); $controller->contructClasses();
// EXECUTE THE REQUESTED ACTION
if ($missingAction)
{
$params['action'] = 'missingAction';
$controller->missingAction = $params['action'];
}
call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']); call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
$isFatal = isset($controller->isFatal) ? $controller->isFatal : false; $isFatal = isset($controller->isFatal) ? $controller->isFatal : false;
@ -376,16 +366,17 @@ class Dispatcher extends Object
* @param array $params * @param array $params
* @since Cake v 0.10.0.172 * @since Cake v 0.10.0.172
*/ */
function scaffoldView ($url, $controller_class, $params) function scaffoldView ($url, &$controller_class, $params)
{ {
if($params['action'] === 'index' || $params['action'] === 'list' || $isDataBaseSet = DboFactory::getInstance($controller_class->useDbConfig);
if(!empty($isDataBaseSet))
{
if($params['action'] === 'index' || $params['action'] === 'list' ||
$params['action'] === 'show' || $params['action'] === 'new' || $params['action'] === 'show' || $params['action'] === 'new' ||
$params['action'] === 'create' || $params['action'] === 'edit' || $params['action'] === 'create' || $params['action'] === 'edit' ||
$params['action'] === 'update' || $params['action'] === 'destroy') $params['action'] === 'update' || $params['action'] === 'destroy')
{ {
$scaffolding = new Scaffold($controller_class, $params); $scaffolding =& new Scaffold($controller_class);
$scaffolding->base = $this->base;
$scaffolding->constructClasses($params);
switch ($params['action']) switch ($params['action'])
{ {
@ -424,9 +415,14 @@ class Dispatcher extends Object
} }
else else
{ {
$this->errorUnknownAction($url, $controller_class, $params['action']); $this->errorUnknownAction($url, get_class($controller_class), $params['action']);
} }
exit; exit;
}
else
{
call_user_func_array(array(&$controller_class, 'missingDatabase'), null);
}
} }
} }
?> ?>

View file

@ -780,7 +780,7 @@ class Model extends Object
function set ($one, $two=null) function set ($one, $two=null)
{ {
$this->validationErrors = null; $this->validationErrors = null;
$data = is_array($one)? array($this->table=>$one) : array($one=>$two); $data = is_array($one)? $one : array($one=>$two);
foreach ($data as $n => $v) foreach ($data as $n => $v)
{ {

View file

@ -105,33 +105,16 @@ class Scaffold extends Object {
* @param string $controller_class Name of controller * @param string $controller_class Name of controller
* @param array $params * @param array $params
*/ */
function __construct($controller_class, $params) function __construct(&$controller_class)
{ {
$this->clazz = $controller_class; $this->controllerClass =& $controller_class;
$this->actionView = $params['action']; $this->clazz =& $controller_class->name;
$this->actionView =& $controller_class->action;
$r = null; $this->modelKey = Inflector::underscore(Inflector::singularize($this->clazz));
if (!preg_match('/(.*)Controller/i', $this->clazz, $r))
{
die("Scaffold::__construct() : Can't get or parse class name.");
}
$this->modelKey = Inflector::underscore(Inflector::singularize($r[1]));
$this->scaffoldTitle = Inflector::humanize($this->modelKey); $this->scaffoldTitle = Inflector::humanize($this->modelKey);
}
/**
* Set up a new class with the given settings.
*
* @param array $params
*/
function constructClasses($params)
{
$this->controllerClass = new $this->clazz();
$this->controllerClass->base = $this->base;
$this->controllerClass->params = $params;
$this->controllerClass->contructClasses();
$this->controllerClass->layout = 'scaffold'; $this->controllerClass->layout = 'scaffold';
$this->controllerClass->pageTitle = $this->scaffoldTitle; $this->controllerClass->pageTitle = $this->scaffoldTitle;
$this->controllerClass->contructClasses();
} }
/** /**

View file

@ -176,12 +176,37 @@ class View extends Object
*/ */
var $modelsLoaded = false; var $modelsLoaded = false;
/**
* Enter description here...
*
* @var boolean
*/
var $controller = null;
/** /**
* Constructor * Constructor
* *
* @return View * @return View
*/ */
function View(){ function View(&$controller)
{
$this->controller =& $controller;
$this->_viewVars =& $this->controller->_viewVars;
$this->action =& $this->controller->action;
$this->autoLayout =& $this->controller->autoLayout;
$this->autoRender =& $this->controller->autoRender;
$this->base =& $this->controller->base;
$this->helpers =& $this->controller->helpers;
$this->here =& $this->controller->here;
$this->layout =& $this->controller->layout;
$this->models =& $this->controller->models;
$this->name =& $this->controller->name;
$this->pageTitle =& $this->controller->pageTitle;
$this->parent =& $this->controller->parent;
$this->viewPath =& $this->controller->viewPath;
$this->params =& $this->controller->params;
$this->data =& $this->controller->data;
$this->displayFields =& $this->controller->displayFields;
} }
/** /**
@ -414,6 +439,7 @@ class View extends Object
function missingController() function missingController()
{ {
//We are simulating action call below, this is not a filename! //We are simulating action call below, this is not a filename!
$this->missingController = $this->name;
$this->render('../errors/missingController'); $this->render('../errors/missingController');
} }
@ -424,6 +450,7 @@ class View extends Object
function missingAction() function missingAction()
{ {
//We are simulating action call below, this is not a filename! //We are simulating action call below, this is not a filename!
$this->missingAction = $this->name;
$this->render('../errors/missingAction'); $this->render('../errors/missingAction');
} }
@ -434,6 +461,7 @@ class View extends Object
function missingView() function missingView()
{ {
//We are simulating action call below, this is not a filename! //We are simulating action call below, this is not a filename!
$this->missingView = $this->name;
$this->render('../errors/missingView'); $this->render('../errors/missingView');
} }