From 29a1ee90439389fc15b6eada10847027a177f108 Mon Sep 17 00:00:00 2001 From: phpnut Date: Sat, 17 Sep 2005 07:56:32 +0000 Subject: [PATCH] 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 --- app/views/errors/missing_database.thtml | 19 ++++++ app/views/errors/missing_view.thtml | 14 ++--- libs/controller.php | 24 +++----- libs/dispatcher.php | 80 ++++++++++++------------- libs/model.php | 2 +- libs/scaffold.php | 29 ++------- libs/view.php | 30 +++++++++- 7 files changed, 107 insertions(+), 91 deletions(-) create mode 100644 app/views/errors/missing_database.thtml diff --git a/app/views/errors/missing_database.thtml b/app/views/errors/missing_database.thtml new file mode 100644 index 000000000..2196cfb31 --- /dev/null +++ b/app/views/errors/missing_database.thtml @@ -0,0 +1,19 @@ +

Scaffold Requires a Database Connection

+ +

Missing Database Connection +

+ +

+Notice: this error is being rendered by the app/views/errors/missing_database.thtml +view file, a user-customizable error page for handling errors within CakePHP. +

+ +1):?> +

Controller dump:

+
+db);
+print_r($this); 
+?>
+
+ \ No newline at end of file diff --git a/app/views/errors/missing_view.thtml b/app/views/errors/missing_view.thtml index 42ecd2996..bfa21c18e 100644 --- a/app/views/errors/missing_view.thtml +++ b/app/views/errors/missing_view.thtml @@ -1,8 +1,8 @@

Missing view

-

You are seeing this error because the view missingView;?> - for action params['action'];?> - in controller name);?> could not be found. +

You are seeing this error because the view missingView;?> + for action params['action'];?> + in controller name);?> could not be found.

@@ -11,14 +11,14 @@ view file, a user-customizable error page for handling missing/invalid views dur

-Fatal: Unable to load view file missingView;?> for -action params['controller'];?>::params['action'];?> +Fatal: Unable to load view file missingView;?> for +action params['controller'];?>::params['action'];?>

-1):?> +1):?>

Controller dump:

-db);
 print_r($this); 
 ?>
diff --git a/libs/controller.php b/libs/controller.php
index 8ebad666d..7417afd27 100644
--- a/libs/controller.php
+++ b/libs/controller.php
@@ -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.
diff --git a/libs/dispatcher.php b/libs/dispatcher.php
index 816432d67..47293a7ec 100644
--- a/libs/dispatcher.php
+++ b/libs/dispatcher.php
@@ -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);
+       }
    }
 }
 ?>
\ No newline at end of file
diff --git a/libs/model.php b/libs/model.php
index 280fcfaef..4d985df17 100644
--- a/libs/model.php
+++ b/libs/model.php
@@ -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) 
       {
diff --git a/libs/scaffold.php b/libs/scaffold.php
index 0a362100a..55c87d423 100644
--- a/libs/scaffold.php
+++ b/libs/scaffold.php
@@ -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();
 	}
 
 	/**
diff --git a/libs/view.php b/libs/view.php
index e06b03051..8d8c9ce3f 100644
--- a/libs/view.php
+++ b/libs/view.php
@@ -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');
    }