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

View file

@ -342,23 +342,7 @@ class Controller extends Object
*/
function render($action=null, $layout=null, $file=null)
{
$view = View::getInstance();
$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;
$view =& new View($this);
if(!empty($this->models))
{
@ -404,6 +388,12 @@ class Controller extends Object
//We are simulating action call below, this is not a filename!
$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.

View file

@ -116,11 +116,9 @@ class Dispatcher extends Object
}
else
{
// create controller
$controller = new $ctrlClass($this);
}
// if action is not set, and the default Controller::index() method doesn't exist
if (empty($params['action']))
{
if (method_exists($controller, 'index'))
@ -129,55 +127,47 @@ class Dispatcher extends Object
}
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;
}
}
// if the requested action doesn't exist
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;
}
if ($missingAction)
{
$controller->missingAction = $params['action'];
$params['action'] = 'missingAction';
}
// initialize the controller
$controller->base = $this->base;
$controller->here = $this->base.'/'.$url;
$controller->params = $params;
$controller->action = $params['action'];
$controller->data = empty($params['data'])? null: $params['data'];
$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();
// 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']);
$isFatal = isset($controller->isFatal) ? $controller->isFatal : false;
@ -376,16 +366,17 @@ class Dispatcher extends Object
* @param array $params
* @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'] === 'create' || $params['action'] === 'edit' ||
$params['action'] === 'update' || $params['action'] === 'destroy')
{
$scaffolding = new Scaffold($controller_class, $params);
$scaffolding->base = $this->base;
$scaffolding->constructClasses($params);
$scaffolding =& new Scaffold($controller_class);
switch ($params['action'])
{
@ -424,9 +415,14 @@ class Dispatcher extends Object
}
else
{
$this->errorUnknownAction($url, $controller_class, $params['action']);
$this->errorUnknownAction($url, get_class($controller_class), $params['action']);
}
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)
{
$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)
{

View file

@ -105,33 +105,16 @@ class Scaffold extends Object {
* @param string $controller_class Name of controller
* @param array $params
*/
function __construct($controller_class, $params)
function __construct(&$controller_class)
{
$this->clazz = $controller_class;
$this->actionView = $params['action'];
$r = null;
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->controllerClass =& $controller_class;
$this->clazz =& $controller_class->name;
$this->actionView =& $controller_class->action;
$this->modelKey = Inflector::underscore(Inflector::singularize($this->clazz));
$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->pageTitle = $this->scaffoldTitle;
$this->controllerClass->contructClasses();
}
/**

View file

@ -175,13 +175,38 @@ class View extends Object
* @var boolean
*/
var $modelsLoaded = false;
/**
* Enter description here...
*
* @var boolean
*/
var $controller = null;
/**
* Constructor
*
* @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()
{
//We are simulating action call below, this is not a filename!
$this->missingController = $this->name;
$this->render('../errors/missingController');
}
@ -424,6 +450,7 @@ class View extends Object
function missingAction()
{
//We are simulating action call below, this is not a filename!
$this->missingAction = $this->name;
$this->render('../errors/missingAction');
}
@ -434,6 +461,7 @@ class View extends Object
function missingView()
{
//We are simulating action call below, this is not a filename!
$this->missingView = $this->name;
$this->render('../errors/missingView');
}