merging changes made in sandboxes

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@893 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-09-18 18:58:45 +00:00
parent a86866a7a1
commit 1a93ab942f
6 changed files with 55 additions and 46 deletions

View file

@ -177,4 +177,10 @@ define ('IMAGES_URL', '/img/');
*/ */
define ('CSS_URL', '/css/'); define ('CSS_URL', '/css/');
/**
* Web path to the js files directory.
*/
define ('JS_URL', '/js/');
?> ?>

View file

@ -54,7 +54,7 @@ function loadModels ()
require (APP.'app_model.php'); require (APP.'app_model.php');
foreach (listClasses(MODELS) as $model_fn) foreach (listClasses(MODELS) as $model_fn)
{ {
require (MODELS.$model_fn); require_once (MODELS.$model_fn);
} }
} }
@ -72,12 +72,12 @@ function loadControllers ()
foreach (listClasses(HELPERS) as $helper) foreach (listClasses(HELPERS) as $helper)
{ {
require (HELPERS.$helper.'.php'); require_once (HELPERS.$helper.'.php');
} }
foreach (listClasses(CONTROLLERS) as $controller) foreach (listClasses(CONTROLLERS) as $controller)
{ {
require (CONTROLLERS.$controller.'.php'); require_once (CONTROLLERS.$controller.'.php');
} }
} }
@ -92,10 +92,10 @@ function loadController ($name)
$controller_fn = CONTROLLERS.Inflector::underscore($name).'_controller.php'; $controller_fn = CONTROLLERS.Inflector::underscore($name).'_controller.php';
$helper_fn = HELPERS.Inflector::underscore($name).'_helper.php'; $helper_fn = HELPERS.Inflector::underscore($name).'_helper.php';
require(APP.'app_controller.php'); require_once(APP.'app_controller.php');
if (file_exists($helper_fn)) if (file_exists($helper_fn))
require($helper_fn); require_once($helper_fn);
return file_exists($controller_fn)? require($controller_fn): false; return file_exists($controller_fn)? require($controller_fn): false;
} }
@ -128,7 +128,7 @@ function config ()
} }
elseif (file_exists(CONFIGS.$arg.'.php')) elseif (file_exists(CONFIGS.$arg.'.php'))
{ {
include (CONFIGS.$arg.'.php'); include_once (CONFIGS.$arg.'.php');
if (count($args) == 1) return true; if (count($args) == 1) return true;
} }
else else

View file

@ -772,9 +772,6 @@ class Controller extends Object
} }
} // end loop through manytomany relations. } // end loop through manytomany relations.
} }
return $fieldNames; return $fieldNames;
} }
} }

View file

@ -85,9 +85,9 @@ class Dispatcher extends Object
* @param string $url URL information to work on. * @param string $url URL information to work on.
* @return boolean Success * @return boolean Success
*/ */
function dispatch($url) function dispatch($url, $additional_params=array())
{ {
$params = $this->parseParams($url); $params = array_merge($this->parseParams($url), $additional_params);
$missingController = false; $missingController = false;
$missingAction = false; $missingAction = false;
$missingView = false; $missingView = false;
@ -119,22 +119,18 @@ class Dispatcher extends Object
{ {
$controller = new $ctrlClass($this); $controller = new $ctrlClass($this);
} }
if (empty($params['action'])) $classMethods = get_class_methods($controller);
$classVars = get_object_vars($controller);
if ((empty($params['action'])) && in_array('index', $classMethods))
{ {
if (method_exists($controller, 'index')) $params['action'] = 'index';
{
$params['action'] = 'index';
}
else
{
$missingAction = true;
}
} }
if (!method_exists($controller, $params['action'])) if(!in_array($params['action'], $classMethods))
{ {
$missingAction = true; $missingAction = true;
} }
$controller->base = $this->base; $controller->base = $this->base;
@ -143,24 +139,22 @@ class Dispatcher extends Object
$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'];
$controller->viewpath = Inflector::underscore($ctrlName);
foreach (get_object_vars($controller) as $name => $value) $controller->autoLayout = !$params['bare'];
if((in_array('scaffold', array_keys($classVars))) && ($missingAction === true || !empty($params['action'])))
{ {
if(($name === 'scaffold' && $missingAction === true) if(!in_array($params['action'], $classMethods))
|| ($name === 'scaffold' && !empty($params['action']))) {
{ if(empty($params['action']))
if (!method_exists($controller, $params['action'])) {
{ $params['action'] = 'index';
if(empty($params['action']))
{
$params['action'] = 'index';
}
$this->scaffoldView($url, $controller, $params);
exit;
} }
$this->scaffoldView($url, $controller, $params);
exit;
} }
} }
$controller->constructClasses(); $controller->constructClasses();
if ($missingAction) if ($missingAction)
@ -226,7 +220,8 @@ class Dispatcher extends Object
{ {
$params['form'][$name] = $data; $params['form'][$name] = $data;
} }
$params['bare'] = empty($params['ajax'])? (empty($params['bare'])? 0: 1): 1;
return $params; return $params;
} }
@ -273,19 +268,24 @@ class Dispatcher extends Object
return preg_match('/^(.*)\/public\/index\.php$/', $script_name, $r)? $r[1]: false; return preg_match('/^(.*)\/public\/index\.php$/', $script_name, $r)? $r[1]: false;
} }
/** /**
* Displays an error page (e.g. 404 Not found). * Displays an error page (e.g. 404 Not found).
* *
* @param int $code Error code (e.g. 404) * @param int $code Error code (e.g. 404)
* @param string $name Name of the error message (e.g. Not found) * @param string $name Name of the error message (e.g. Not found)
* @param string $message * @param string $message
* @return unknown
*/ */
function error ($code, $name, $message) function error ($code, $name, $message)
{ {
$controller = new Controller ($this); $controller = new Controller ($this);
$controller->base = $this->base; $controller->base = $this->base;
$controller->error($code, $name, $message); $controller->autoLayout = false;
} $controller->set(array('code'=>$code, 'name'=>$name, 'message'=>$message));
return $controller->render('layouts/error');
}
/** /**
* Convenience method to display a 404 page. * Convenience method to display a 404 page.

View file

@ -140,7 +140,8 @@ class Router extends Object {
array() array()
); );
$this->connect('/bare/:controller/:action/*', array('bare'=>'1'));
$this->connect('/ajax/:controller/:action/*', array('bare'=>'1'));
$this->routes[] = $admin_route; $this->routes[] = $admin_route;
$this->routes[] = $default_route; $this->routes[] = $default_route;

View file

@ -552,7 +552,12 @@ class View extends Object
return $out; return $out;
} }
function fetch ($url)
{
$dispatcher = new Dispatcher();
return $dispatcher->dispatch($url, array('bare'=>1));
}
} }
?> ?>