2005-06-21 23:44:49 +00:00
|
|
|
<?php
|
2005-08-21 06:49:02 +00:00
|
|
|
/* SVN FILE: $Id$ */
|
2005-06-21 23:44:49 +00:00
|
|
|
|
|
|
|
/**
|
2005-12-24 07:56:48 +00:00
|
|
|
* Dispatcher takes the URL information, parses it for paramters and
|
2005-09-17 02:22:07 +00:00
|
|
|
* tells the involved controllers what to do.
|
2005-12-24 07:56:48 +00:00
|
|
|
*
|
|
|
|
* This is the heart of Cake's operation.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
|
|
|
* PHP versions 4 and 5
|
|
|
|
*
|
|
|
|
* CakePHP : Rapid Development Framework <http://www.cakephp.org/>
|
2005-12-24 07:56:48 +00:00
|
|
|
* Copyright (c) 2005, Cake Software Foundation, Inc.
|
2005-12-23 21:57:26 +00:00
|
|
|
* 1785 E. Sahara Avenue, Suite 490-204
|
|
|
|
* Las Vegas, Nevada 89104
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-23 21:57:26 +00:00
|
|
|
* Licensed under The MIT License
|
|
|
|
* Redistributions of files must retain the above copyright notice.
|
2005-08-21 06:49:02 +00:00
|
|
|
*
|
2005-12-24 07:56:48 +00:00
|
|
|
* @filesource
|
2005-12-23 21:57:26 +00:00
|
|
|
* @copyright Copyright (c) 2005, Cake Software Foundation, Inc.
|
|
|
|
* @link http://www.cakefoundation.org/projects/info/cakephp CakePHP Project
|
2005-08-21 06:49:02 +00:00
|
|
|
* @package cake
|
2005-10-09 01:56:21 +00:00
|
|
|
* @subpackage cake.cake
|
2005-08-21 06:49:02 +00:00
|
|
|
* @since CakePHP v 0.2.9
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
2005-06-21 23:44:49 +00:00
|
|
|
* @lastmodified $Date$
|
2005-08-21 06:49:02 +00:00
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
2005-06-21 23:44:49 +00:00
|
|
|
*/
|
|
|
|
|
2005-07-04 04:16:20 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* List of helpers to include
|
2005-07-04 04:16:20 +00:00
|
|
|
*/
|
2005-12-27 03:33:44 +00:00
|
|
|
uses('error_messages', 'router', DS.'controller'.DS.'controller');
|
2005-06-21 23:44:49 +00:00
|
|
|
|
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Dispatcher translates URLs to controller-action-paramter triads.
|
2005-12-22 01:07:28 +00:00
|
|
|
*
|
2005-06-21 23:44:49 +00:00
|
|
|
* Dispatches the request, creating appropriate models and controllers.
|
|
|
|
*
|
2005-08-21 06:49:02 +00:00
|
|
|
* @package cake
|
2005-10-09 01:56:21 +00:00
|
|
|
* @subpackage cake.cake
|
2005-08-21 06:49:02 +00:00
|
|
|
* @since CakePHP v 0.2.9
|
2005-06-21 23:44:49 +00:00
|
|
|
*/
|
|
|
|
class Dispatcher extends Object
|
|
|
|
{
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Base URL
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $base = false;
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-10-28 08:25:31 +00:00
|
|
|
/**
|
|
|
|
* Base URL
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $admin = false;
|
2005-07-10 05:08:19 +00:00
|
|
|
|
2005-12-22 01:07:28 +00:00
|
|
|
/**
|
|
|
|
* Base URL
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
var $webservices = null;
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Constructor.
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
|
|
|
function __construct()
|
|
|
|
{
|
|
|
|
parent::__construct();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2005-09-17 02:22:07 +00:00
|
|
|
* Dispatches and invokes given URL, handing over control to the involved controllers, and then renders the results (if autoRender is set).
|
|
|
|
*
|
2005-12-22 01:07:28 +00:00
|
|
|
* If no controller of given name can be found, invoke() shows error messages in
|
|
|
|
* the form of Missing Controllers information. It does the same with Actions (methods of Controllers are called
|
2005-09-17 02:22:07 +00:00
|
|
|
* Actions).
|
2005-07-10 05:08:19 +00:00
|
|
|
*
|
2005-12-27 03:33:44 +00:00
|
|
|
* @param string $url URL information to work on.
|
|
|
|
* @return boolean Success
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2005-09-19 20:07:16 +00:00
|
|
|
function dispatch($url, $additionalParams=array())
|
2005-07-10 05:08:19 +00:00
|
|
|
{
|
2005-09-19 20:07:16 +00:00
|
|
|
$params = array_merge($this->parseParams($url), $additionalParams);
|
2005-07-10 05:08:19 +00:00
|
|
|
$missingController = false;
|
|
|
|
$missingAction = false;
|
|
|
|
$missingView = false;
|
2005-10-18 22:27:39 +00:00
|
|
|
$privateAction = false;
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-10-28 08:25:31 +00:00
|
|
|
if(defined('CAKE_ADMIN'))
|
|
|
|
{
|
|
|
|
if(isset($params[CAKE_ADMIN]))
|
|
|
|
{
|
|
|
|
$this->admin = '/'.CAKE_ADMIN ;
|
|
|
|
$url = preg_replace('/'.CAKE_ADMIN.'\//', '', $url);
|
|
|
|
if (empty($params['action']))
|
|
|
|
{
|
|
|
|
$params['action'] = CAKE_ADMIN.'_'.'index';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$params['action'] = CAKE_ADMIN.'_'.$params['action'];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-10-28 08:25:31 +00:00
|
|
|
$this->base = $this->baseUrl();
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
if (empty($params['controller']))
|
|
|
|
{
|
|
|
|
$missingController = true;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$ctrlName = Inflector::camelize($params['controller']);
|
|
|
|
$ctrlClass = $ctrlName.'Controller';
|
|
|
|
|
2005-12-27 17:14:32 +00:00
|
|
|
if(!class_exists($ctrlClass))
|
2005-07-10 05:08:19 +00:00
|
|
|
{
|
2005-12-27 17:14:32 +00:00
|
|
|
if (!loadController($ctrlName))
|
2005-10-09 01:56:21 +00:00
|
|
|
{
|
2005-12-27 17:14:32 +00:00
|
|
|
if(preg_match('/([\\.]+)/',$ctrlName))
|
|
|
|
{
|
|
|
|
$this->error404(strtolower($ctrlName),'Was not found on this server');
|
|
|
|
exit();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$missingController = true;
|
|
|
|
}
|
2005-10-09 01:56:21 +00:00
|
|
|
}
|
2005-07-10 05:08:19 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($missingController)
|
|
|
|
{
|
[1258]
Author: phpnut
Date: 8:13:45 PM, Friday, October 28, 2005
Message:
adding version text file
[1257]
Author: phpnut
Date: 8:03:24 PM, Friday, October 28, 2005
Message:
small typo in last commit
[1256]
Author: phpnut
Date: 7:16:50 PM, Friday, October 28, 2005
Message:
Added fix for a self join of 1 to 1 associations.
This is automatic and adds Child_ to the joined class for hasOne or belongsTo.
Scaffold is updated to work with this change.
You will have to consider the Child_ prefix when working with self joins.
[1253]
Author: phpnut
Date: 4:07:55 PM, Friday, October 28, 2005
Message:
Fixed problem with session cookies being set for each path in the URL.
Added char to switch in Controller::generateFieldNames()
[1252]
Author: phpnut
Date: 1:59:49 PM, Friday, October 28, 2005
Message:
Updated routes.php.default with change to route case.
Removed debug code I had added to Model::findAll
[1251]
Author: phpnut
Date: 1:51:00 PM, Friday, October 28, 2005
Message:
Added a fix for class already defined error.
Updated core.php docblock with level 3 setting for DEBUG.
Change instances of AppController to Controller for loading error messages.
Updated 404 errors to use default layout
[1250]
Author: phpnut
Date: 1:34:08 PM, Friday, October 28, 2005
Message:
renaming error or error404
[1249]
Author: phpnut
Date: 1:32:51 PM, Friday, October 28, 2005
Message:
moving error.thtml to errors directory
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1259 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-29 01:21:47 +00:00
|
|
|
$controller =& new Controller();
|
2005-07-10 05:08:19 +00:00
|
|
|
$params['action'] = 'missingController';
|
2005-10-28 08:33:35 +00:00
|
|
|
if (empty($params['controller']))
|
|
|
|
{
|
|
|
|
$params['controller'] = "Controller";
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
$params['controller'] = Inflector::camelize($params['controller']."Controller");
|
|
|
|
}
|
2005-07-10 05:08:19 +00:00
|
|
|
$controller->missingController = $params['controller'];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-03 04:48:00 +00:00
|
|
|
$controller =& new $ctrlClass($this);
|
2005-07-10 05:08:19 +00:00
|
|
|
}
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-09-18 18:58:45 +00:00
|
|
|
$classMethods = get_class_methods($controller);
|
|
|
|
$classVars = get_object_vars($controller);
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-09-19 20:07:16 +00:00
|
|
|
if (empty($params['action']))
|
2005-07-10 05:08:19 +00:00
|
|
|
{
|
2005-09-18 18:58:45 +00:00
|
|
|
$params['action'] = 'index';
|
2005-07-10 05:08:19 +00:00
|
|
|
}
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-12-24 07:56:48 +00:00
|
|
|
if((in_array($params['action'], $classMethods) || in_array(strtolower($params['action']), $classMethods)) && strpos($params['action'], '_', 0) === 0)
|
2005-10-18 22:27:39 +00:00
|
|
|
{
|
|
|
|
$privateAction = true;
|
|
|
|
}
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-12-24 07:56:48 +00:00
|
|
|
if(!in_array($params['action'], $classMethods) && !in_array(strtolower($params['action']), $classMethods))
|
2005-07-10 05:08:19 +00:00
|
|
|
{
|
2005-09-18 18:58:45 +00:00
|
|
|
$missingAction = true;
|
2005-07-10 05:08:19 +00:00
|
|
|
}
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-12-29 06:45:33 +00:00
|
|
|
if(in_array('return', array_keys($params)) && $params['return'] == 1)
|
2005-12-29 05:07:12 +00:00
|
|
|
{
|
2005-12-29 06:45:33 +00:00
|
|
|
$controller->autoRender = false;
|
2005-12-29 05:07:12 +00:00
|
|
|
}
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
$controller->base = $this->base;
|
|
|
|
$controller->here = $this->base.'/'.$url;
|
2005-10-03 04:48:00 +00:00
|
|
|
$controller->webroot = $this->webroot;
|
2005-07-10 05:08:19 +00:00
|
|
|
$controller->params = $params;
|
|
|
|
$controller->action = $params['action'];
|
|
|
|
$controller->data = empty($params['data'])? null: $params['data'];
|
|
|
|
$controller->passed_args = empty($params['pass'])? null: $params['pass'];
|
2005-09-18 18:58:45 +00:00
|
|
|
$controller->autoLayout = !$params['bare'];
|
2005-12-22 01:07:28 +00:00
|
|
|
$controller->webservices = $params['webservices'];
|
2005-09-18 18:58:45 +00:00
|
|
|
|
2005-12-22 01:07:28 +00:00
|
|
|
if(!is_null($controller->webservices))
|
[1285]
Author: phpnut
Date: 10:09:03 PM, Monday, October 31, 2005
Message:
Removed references in the Session class
[1283]
Author: phpnut
Date: 8:47:37 PM, Monday, October 31, 2005
Message:
Added fix to the Controller::constructClassess().
The database should have an instance available if a component will use it.
[1282]
Author: phpnut
Date: 8:36:07 PM, Monday, October 31, 2005
Message:
Updated the Model association methods to correct and error I introduced when reactoring last week.
Added a return from each of the settings in Security::inactiveMins(); This class is not fully implemented.
Updated scaffold and dipatcher with changes to the session class.
Fixed problem with session not working properly.
Added a regenrate id for sessions.
When CAKE_SECURITY is set to high this will regenrate a new session key on each request.
The old session file will be removed from the file system. This is a added security measure.
[1270]
Author: phpnut
Date: 1:55:28 PM, Sunday, October 30, 2005
Message:
Updated Session class to regenrate a new session key on each request when security level set to high.
Updated doc comments in some classes
[1269]
Author: phpnut
Date: 9:49:43 AM, Sunday, October 30, 2005
Message:
Added a fix for Ticket #105
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1286 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-11-01 04:20:28 +00:00
|
|
|
{
|
2005-12-22 01:07:28 +00:00
|
|
|
array_push($controller->components, $controller->webservices);
|
|
|
|
array_push($controller->helpers, $controller->webservices);
|
[1285]
Author: phpnut
Date: 10:09:03 PM, Monday, October 31, 2005
Message:
Removed references in the Session class
[1283]
Author: phpnut
Date: 8:47:37 PM, Monday, October 31, 2005
Message:
Added fix to the Controller::constructClassess().
The database should have an instance available if a component will use it.
[1282]
Author: phpnut
Date: 8:36:07 PM, Monday, October 31, 2005
Message:
Updated the Model association methods to correct and error I introduced when reactoring last week.
Added a return from each of the settings in Security::inactiveMins(); This class is not fully implemented.
Updated scaffold and dipatcher with changes to the session class.
Fixed problem with session not working properly.
Added a regenrate id for sessions.
When CAKE_SECURITY is set to high this will regenrate a new session key on each request.
The old session file will be removed from the file system. This is a added security measure.
[1270]
Author: phpnut
Date: 1:55:28 PM, Sunday, October 30, 2005
Message:
Updated Session class to regenrate a new session key on each request when security level set to high.
Updated doc comments in some classes
[1269]
Author: phpnut
Date: 9:49:43 AM, Sunday, October 30, 2005
Message:
Added a fix for Ticket #105
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1286 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-11-01 04:20:28 +00:00
|
|
|
}
|
|
|
|
|
2005-09-19 20:07:16 +00:00
|
|
|
if((in_array('scaffold', array_keys($classVars))) && ($missingAction === true))
|
2005-09-17 07:56:32 +00:00
|
|
|
{
|
2005-12-27 03:33:44 +00:00
|
|
|
uses(DS.'controller'.DS.'scaffold');
|
[1285]
Author: phpnut
Date: 10:09:03 PM, Monday, October 31, 2005
Message:
Removed references in the Session class
[1283]
Author: phpnut
Date: 8:47:37 PM, Monday, October 31, 2005
Message:
Added fix to the Controller::constructClassess().
The database should have an instance available if a component will use it.
[1282]
Author: phpnut
Date: 8:36:07 PM, Monday, October 31, 2005
Message:
Updated the Model association methods to correct and error I introduced when reactoring last week.
Added a return from each of the settings in Security::inactiveMins(); This class is not fully implemented.
Updated scaffold and dipatcher with changes to the session class.
Fixed problem with session not working properly.
Added a regenrate id for sessions.
When CAKE_SECURITY is set to high this will regenrate a new session key on each request.
The old session file will be removed from the file system. This is a added security measure.
[1270]
Author: phpnut
Date: 1:55:28 PM, Sunday, October 30, 2005
Message:
Updated Session class to regenrate a new session key on each request when security level set to high.
Updated doc comments in some classes
[1269]
Author: phpnut
Date: 9:49:43 AM, Sunday, October 30, 2005
Message:
Added a fix for Ticket #105
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1286 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-11-01 04:20:28 +00:00
|
|
|
$scaffolding = new Scaffold($controller, $params);
|
2005-09-19 20:07:16 +00:00
|
|
|
exit;
|
2005-09-17 07:56:32 +00:00
|
|
|
}
|
2005-09-18 18:58:45 +00:00
|
|
|
|
2005-09-18 13:25:20 +00:00
|
|
|
$controller->constructClasses();
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-09-17 07:56:32 +00:00
|
|
|
if ($missingAction)
|
|
|
|
{
|
|
|
|
$controller->missingAction = $params['action'];
|
2005-09-19 20:07:16 +00:00
|
|
|
$params['action'] = 'missingAction';
|
2005-09-17 07:56:32 +00:00
|
|
|
}
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-10-18 22:27:39 +00:00
|
|
|
if ($privateAction)
|
|
|
|
{
|
|
|
|
$controller->privateAction = $params['action'];
|
|
|
|
$params['action'] = 'privateAction';
|
|
|
|
}
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-09-19 20:07:16 +00:00
|
|
|
return $this->_invoke($controller, $params );
|
|
|
|
}
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-09-19 20:07:16 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Invokes given controller's render action if autoRender option is set. Otherwise the contents of the operation are returned as a string.
|
2005-09-19 20:07:16 +00:00
|
|
|
*
|
2005-10-18 22:27:39 +00:00
|
|
|
* @param object $controller
|
|
|
|
* @param array $params
|
|
|
|
* @return string
|
2005-09-19 20:07:16 +00:00
|
|
|
*/
|
|
|
|
function _invoke (&$controller, $params )
|
|
|
|
{
|
|
|
|
$output = call_user_func_array(array(&$controller, $params['action']), empty($params['pass'])? null: $params['pass']);
|
|
|
|
if ($controller->autoRender)
|
|
|
|
{
|
2005-12-28 17:23:12 +00:00
|
|
|
return $controller->render();
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
return $output;
|
2005-09-19 20:07:16 +00:00
|
|
|
}
|
2005-07-10 05:08:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Returns array of GET and POST parameters. GET parameters are taken from given URL.
|
|
|
|
*
|
2005-12-27 03:33:44 +00:00
|
|
|
* @param string $from_url URL to mine for parameter information.
|
2005-07-10 05:08:19 +00:00
|
|
|
* @return array Parameters found in POST and GET.
|
|
|
|
*/
|
|
|
|
function parseParams($from_url)
|
|
|
|
{
|
2005-09-19 20:07:16 +00:00
|
|
|
// load routes config
|
|
|
|
$Route = new Router();
|
|
|
|
include CONFIGS.'routes.php';
|
|
|
|
$params = $Route->parse ($from_url);
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-09-19 20:07:16 +00:00
|
|
|
// add submitted form data
|
|
|
|
$params['form'] = $_POST;
|
|
|
|
if (isset($_POST['data']))
|
|
|
|
{
|
|
|
|
$params['data'] = (ini_get('magic_quotes_gpc') == 1)?
|
|
|
|
$this->stripslashes_deep($_POST['data']) : $_POST['data'];
|
|
|
|
}
|
|
|
|
if (isset($_GET))
|
|
|
|
{
|
|
|
|
$params['url'] = $this->urldecode_deep($_GET);
|
|
|
|
$params['url'] = (ini_get('magic_quotes_gpc') == 1)?
|
|
|
|
$this->stripslashes_deep($params['url']) : $params['url'];
|
|
|
|
}
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-09-19 20:07:16 +00:00
|
|
|
foreach ($_FILES as $name => $data)
|
|
|
|
{
|
|
|
|
$params['form'][$name] = $data;
|
|
|
|
}
|
|
|
|
$params['bare'] = empty($params['ajax'])? (empty($params['bare'])? 0: 1): 1;
|
2005-09-21 05:48:09 +00:00
|
|
|
|
2005-12-23 21:57:26 +00:00
|
|
|
$params['webservices'] = empty($params['webservices']) ? null : $params['webservices'];
|
|
|
|
|
2005-09-19 20:07:16 +00:00
|
|
|
return $params;
|
2005-07-10 05:08:19 +00:00
|
|
|
}
|
|
|
|
|
2005-08-26 04:03:51 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Recursively strips slashes from given array.
|
2005-08-26 04:03:51 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
function stripslashes_deep($val)
|
|
|
|
{
|
2005-12-22 01:07:28 +00:00
|
|
|
return (is_array($val)) ?
|
2005-08-26 04:03:51 +00:00
|
|
|
array_map(array('Dispatcher','stripslashes_deep'), $val) : stripslashes($val);
|
|
|
|
}
|
|
|
|
|
2005-09-17 02:22:07 +00:00
|
|
|
/**
|
2005-10-18 22:27:39 +00:00
|
|
|
* Recursively performs urldecode on given array.
|
2005-09-17 02:22:07 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
function urldecode_deep($val)
|
|
|
|
{
|
2005-12-22 01:07:28 +00:00
|
|
|
return (is_array($val)) ?
|
2005-09-17 02:22:07 +00:00
|
|
|
array_map(array('Dispatcher','urldecode_deep'), $val) : urldecode($val);
|
|
|
|
}
|
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Returns a base URL.
|
|
|
|
*
|
2005-12-27 03:33:44 +00:00
|
|
|
* @return string Base URL
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
2005-10-04 06:39:40 +00:00
|
|
|
function baseUrl()
|
|
|
|
{
|
|
|
|
$htaccess = null;
|
2005-10-28 08:25:31 +00:00
|
|
|
$base = $this->admin;
|
2005-10-04 06:39:40 +00:00
|
|
|
$this->webroot = '';
|
|
|
|
if (defined('BASE_URL'))
|
|
|
|
{
|
2005-10-28 08:25:31 +00:00
|
|
|
$base = BASE_URL.$this->admin;
|
2005-10-04 06:39:40 +00:00
|
|
|
}
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-10-04 06:39:40 +00:00
|
|
|
$docRoot = $_SERVER['DOCUMENT_ROOT'];
|
|
|
|
$scriptName = $_SERVER['PHP_SELF'];
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-10-04 06:39:40 +00:00
|
|
|
// If document root ends with 'webroot', it's probably correctly set
|
2005-07-10 05:08:19 +00:00
|
|
|
$r = null;
|
2005-10-04 06:39:40 +00:00
|
|
|
if (preg_match('/'.APP_DIR.'\\'.DS.WEBROOT_DIR.'/', $docRoot))
|
2005-10-03 04:48:00 +00:00
|
|
|
{
|
2005-10-04 06:39:40 +00:00
|
|
|
$this->webroot = '/';
|
|
|
|
if (preg_match('/^(.*)\/index\.php$/', $scriptName, $r))
|
2005-10-03 04:48:00 +00:00
|
|
|
{
|
|
|
|
if(!empty($r[1]))
|
|
|
|
{
|
[1210]
Author: phpnut
Date: 4:44:45 AM, Wednesday, October 26, 2005
Message:
AJAX is now available as a by default in the $html variable in the templates.
You access it like this:
$html->Ajax->xxx();
Updated default templates.
[1208]
Author: phpnut
Date: 6:49:26 PM, Tuesday, October 25, 2005
Message:
Adding fix in Controller::generateFieldNames();
[1203]
Author: phpnut
Date: 10:40:28 AM, Tuesday, October 25, 2005
Message:
Changes made to core templates and css.
Fixed added for Ticket #60
[1202]
Author: phpnut
Date: 2:30:58 AM, Tuesday, October 25, 2005
Message:
Fix for cake error templates
Fixed a key for tables that are underscored in scaffolded code.
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1211 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-26 10:55:44 +00:00
|
|
|
return $base.$r[1];
|
2005-10-03 04:48:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-07-10 05:08:19 +00:00
|
|
|
else
|
2005-10-03 04:48:00 +00:00
|
|
|
{
|
2005-10-04 06:39:40 +00:00
|
|
|
if (defined('BASE_URL'))
|
|
|
|
{
|
|
|
|
$webroot =setUri();
|
|
|
|
$htaccess = preg_replace('/(?:'.APP_DIR.'(.*)|index\\.php(.*))/i', '', $webroot).APP_DIR.'/'.WEBROOT_DIR.'/';
|
|
|
|
}
|
|
|
|
if(APP_DIR === 'app')
|
|
|
|
{
|
|
|
|
if (preg_match('/^(.*)\\/'.APP_DIR.'\\/'.WEBROOT_DIR.'\\/index\\.php$/', $scriptName, $regs))
|
2005-10-03 04:48:00 +00:00
|
|
|
{
|
2005-10-04 06:39:40 +00:00
|
|
|
!empty($htaccess)? $this->webroot = $htaccess : $this->webroot = $regs[1].'/';
|
|
|
|
return $regs[1];
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
!empty($htaccess)? $this->webroot = $htaccess : $this->webroot = '/';
|
|
|
|
return $base;
|
2005-10-03 04:48:00 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-04 06:39:40 +00:00
|
|
|
if (preg_match('/^(.*)\\/'.WEBROOT_DIR.'\\/index\\.php$/', $scriptName, $regs))
|
2005-10-03 04:48:00 +00:00
|
|
|
{
|
2005-10-04 06:39:40 +00:00
|
|
|
!empty($htaccess)? $this->webroot = $htaccess : $this->webroot = $regs[1].'/';
|
|
|
|
return $regs[1];
|
2005-10-03 04:48:00 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2005-10-04 06:39:40 +00:00
|
|
|
!empty($htaccess)? $this->webroot = $htaccess : $this->webroot = '/';
|
2005-10-03 04:48:00 +00:00
|
|
|
return $base;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2005-10-04 06:39:40 +00:00
|
|
|
return $base;
|
2005-07-10 05:08:19 +00:00
|
|
|
}
|
2005-12-22 01:07:28 +00:00
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
/**
|
|
|
|
* Displays an error page (e.g. 404 Not found).
|
|
|
|
*
|
2005-12-27 03:33:44 +00:00
|
|
|
* @param int $code Error code (e.g. 404)
|
|
|
|
* @param string $name Name of the error message (e.g. Not found)
|
2005-07-10 05:08:19 +00:00
|
|
|
* @param string $message
|
2005-09-18 18:58:45 +00:00
|
|
|
* @return unknown
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
|
|
|
function error ($code, $name, $message)
|
2005-12-27 03:33:44 +00:00
|
|
|
{
|
2005-10-09 01:56:21 +00:00
|
|
|
$controller =& new Controller ($this);
|
2005-09-18 18:58:45 +00:00
|
|
|
$controller->base = $this->base;
|
[1258]
Author: phpnut
Date: 8:13:45 PM, Friday, October 28, 2005
Message:
adding version text file
[1257]
Author: phpnut
Date: 8:03:24 PM, Friday, October 28, 2005
Message:
small typo in last commit
[1256]
Author: phpnut
Date: 7:16:50 PM, Friday, October 28, 2005
Message:
Added fix for a self join of 1 to 1 associations.
This is automatic and adds Child_ to the joined class for hasOne or belongsTo.
Scaffold is updated to work with this change.
You will have to consider the Child_ prefix when working with self joins.
[1253]
Author: phpnut
Date: 4:07:55 PM, Friday, October 28, 2005
Message:
Fixed problem with session cookies being set for each path in the URL.
Added char to switch in Controller::generateFieldNames()
[1252]
Author: phpnut
Date: 1:59:49 PM, Friday, October 28, 2005
Message:
Updated routes.php.default with change to route case.
Removed debug code I had added to Model::findAll
[1251]
Author: phpnut
Date: 1:51:00 PM, Friday, October 28, 2005
Message:
Added a fix for class already defined error.
Updated core.php docblock with level 3 setting for DEBUG.
Change instances of AppController to Controller for loading error messages.
Updated 404 errors to use default layout
[1250]
Author: phpnut
Date: 1:34:08 PM, Friday, October 28, 2005
Message:
renaming error or error404
[1249]
Author: phpnut
Date: 1:32:51 PM, Friday, October 28, 2005
Message:
moving error.thtml to errors directory
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1259 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-29 01:21:47 +00:00
|
|
|
$controller->autoLayout = true;
|
2005-09-18 18:58:45 +00:00
|
|
|
$controller->set(array('code'=>$code, 'name'=>$name, 'message'=>$message));
|
2005-12-27 03:33:44 +00:00
|
|
|
$controller->pageTitle = $code.' '. $name;
|
[1258]
Author: phpnut
Date: 8:13:45 PM, Friday, October 28, 2005
Message:
adding version text file
[1257]
Author: phpnut
Date: 8:03:24 PM, Friday, October 28, 2005
Message:
small typo in last commit
[1256]
Author: phpnut
Date: 7:16:50 PM, Friday, October 28, 2005
Message:
Added fix for a self join of 1 to 1 associations.
This is automatic and adds Child_ to the joined class for hasOne or belongsTo.
Scaffold is updated to work with this change.
You will have to consider the Child_ prefix when working with self joins.
[1253]
Author: phpnut
Date: 4:07:55 PM, Friday, October 28, 2005
Message:
Fixed problem with session cookies being set for each path in the URL.
Added char to switch in Controller::generateFieldNames()
[1252]
Author: phpnut
Date: 1:59:49 PM, Friday, October 28, 2005
Message:
Updated routes.php.default with change to route case.
Removed debug code I had added to Model::findAll
[1251]
Author: phpnut
Date: 1:51:00 PM, Friday, October 28, 2005
Message:
Added a fix for class already defined error.
Updated core.php docblock with level 3 setting for DEBUG.
Change instances of AppController to Controller for loading error messages.
Updated 404 errors to use default layout
[1250]
Author: phpnut
Date: 1:34:08 PM, Friday, October 28, 2005
Message:
renaming error or error404
[1249]
Author: phpnut
Date: 1:32:51 PM, Friday, October 28, 2005
Message:
moving error.thtml to errors directory
git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1259 3807eeeb-6ff5-0310-8944-8be069107fe0
2005-10-29 01:21:47 +00:00
|
|
|
return $controller->render('errors/error404');
|
2005-12-27 03:33:44 +00:00
|
|
|
}
|
2005-09-18 18:58:45 +00:00
|
|
|
|
2005-07-10 05:08:19 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Convenience method to display a 404 page.
|
|
|
|
*
|
2005-12-27 03:33:44 +00:00
|
|
|
* @param string $url URL that spawned this message, to be included in the output.
|
|
|
|
* @param string $message Message text for the 404 page.
|
2005-07-10 05:08:19 +00:00
|
|
|
*/
|
|
|
|
function error404 ($url, $message)
|
|
|
|
{
|
2005-12-24 07:56:48 +00:00
|
|
|
header("HTTP/1.0 404 Not Found");
|
2005-07-10 05:08:19 +00:00
|
|
|
$this->error('404', 'Not found', sprintf(ERROR_404, $url, $message));
|
|
|
|
}
|
2005-07-21 04:02:32 +00:00
|
|
|
}
|
|
|
|
?>
|