Revision: 1245

Author: phpnut
Date: 3:20:08 AM, Friday, October 28, 2005
Message:
Adding fix for Ticket #107

Revision: 1244
Author: phpnut
Date: 2:18:00 AM, Friday, October 28, 2005
Message:
Adding config setting to allow setting a admin path that can access admin methods only on a controller.
Added ability to add objects to the session.
Updated some scaffold templates.



git-svn-id: https://svn.cakephp.org/repo/trunk/cake@1246 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-10-28 08:25:31 +00:00
parent fd83675465
commit 550c5e22e9
12 changed files with 114 additions and 46 deletions

View file

@ -83,6 +83,15 @@ define('CAKE_SECURITY', 'high');
*/ */
define('CAKE_SESSION_SAVE', 'php'); define('CAKE_SESSION_SAVE', 'php');
/**
* Uncomment the define below to use cake built in admin routes.
* You can set this value to anything you want.
* All methods related to the admin route should be prefixed with the
* name you set CAKE_ADMIN to.
* For example: admin_index, admin_edit
*/
//define('CAKE_ADMIN', 'admin');
/** /**
* Compress output CSS (removing comments, whitespace, repeating tags etc.) * Compress output CSS (removing comments, whitespace, repeating tags etc.)
* This requires a /var/cache directory to be writable by the web server (caching). * This requires a /var/cache directory to be writable by the web server (caching).

View file

@ -128,13 +128,6 @@ uses('folder');
require_once CAKE.'dispatcher.php'; require_once CAKE.'dispatcher.php';
require_once LIBS.'model'.DS.'dbo'.DS.'dbo_factory.php'; require_once LIBS.'model'.DS.'dbo'.DS.'dbo_factory.php';
if(!defined('AUTO_SESSION') || AUTO_SESSION == true)
{
// Starts the session unless AUTO_SESSION is explicitly set to false in config/core
//session_start();
$session =& CakeSession::getInstance();
}
config('database'); config('database');
if (class_exists('DATABASE_CONFIG')) if (class_exists('DATABASE_CONFIG'))

View file

@ -54,6 +54,12 @@ class Dispatcher extends Object
*/ */
var $base = false; var $base = false;
/**
* Base URL
* @var string
*/
var $admin = false;
/** /**
* Constructor. * Constructor.
*/ */
@ -74,13 +80,31 @@ class Dispatcher extends Object
*/ */
function dispatch($url, $additionalParams=array()) function dispatch($url, $additionalParams=array())
{ {
$this->base = $this->baseUrl();
$params = array_merge($this->parseParams($url), $additionalParams); $params = array_merge($this->parseParams($url), $additionalParams);
$missingController = false; $missingController = false;
$missingAction = false; $missingAction = false;
$missingView = false; $missingView = false;
$privateAction = false; $privateAction = false;
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'];
}
}
}
$this->base = $this->baseUrl();
if(!in_array('render', array_keys($params))) if(!in_array('render', array_keys($params)))
{ {
$params['render'] = 0; $params['render'] = 0;
@ -111,6 +135,7 @@ class Dispatcher extends Object
if ($missingController) if ($missingController)
{ {
require_once(CAKE.'app_controller.php');
$controller =& new AppController(); $controller =& new AppController();
$params['action'] = 'missingController'; $params['action'] = 'missingController';
$params['controller'] = Inflector::camelize($params['controller']."Controller"); $params['controller'] = Inflector::camelize($params['controller']."Controller");
@ -170,7 +195,11 @@ class Dispatcher extends Object
$controller->privateAction = $params['action']; $controller->privateAction = $params['action'];
$params['action'] = 'privateAction'; $params['action'] = 'privateAction';
} }
if(!defined('AUTO_SESSION') || AUTO_SESSION == true)
{
session_write_close();
$session =& CakeSession::getInstance();
}
return $this->_invoke($controller, $params ); return $this->_invoke($controller, $params );
} }
@ -256,11 +285,11 @@ class Dispatcher extends Object
function baseUrl() function baseUrl()
{ {
$htaccess = null; $htaccess = null;
$base = null; $base = $this->admin;
$this->webroot = ''; $this->webroot = '';
if (defined('BASE_URL')) if (defined('BASE_URL'))
{ {
$base = BASE_URL; $base = BASE_URL.$this->admin;
} }
$docRoot = $_SERVER['DOCUMENT_ROOT']; $docRoot = $_SERVER['DOCUMENT_ROOT'];

View file

@ -54,6 +54,8 @@ class Session extends Object
/** /**
* Enter description here... * Enter description here...
* *
* Use like this. $this->session->write('Controller.sessKey', 'session value');
*
* @param unknown_type $name * @param unknown_type $name
* @param unknown_type $value * @param unknown_type $value
* @return unknown * @return unknown
@ -66,6 +68,8 @@ class Session extends Object
/** /**
* Enter description here... * Enter description here...
* *
* Use like this. $this->session->read('Controller.sessKey');
*
* @param unknown_type $name * @param unknown_type $name
* @return unknown * @return unknown
*/ */
@ -77,6 +81,8 @@ class Session extends Object
/** /**
* Enter description here... * Enter description here...
* *
* Use like this. $this->session->del('Controller.sessKey');
*
* @param unknown_type $name * @param unknown_type $name
* @return unknown * @return unknown
*/ */
@ -88,6 +94,8 @@ class Session extends Object
/** /**
* Enter description here... * Enter description here...
* *
* Use like this. $this->session->check('Controller.sessKey');
*
* @param unknown_type $name * @param unknown_type $name
* @return unknown * @return unknown
*/ */
@ -112,9 +120,9 @@ class Session extends Object
* @param unknown_type $name * @param unknown_type $name
* @return unknown * @return unknown
*/ */
function valid($name) function valid()
{ {
return CakeSession::isValid($name); return CakeSession::isValid();
} }
} }

View file

@ -297,9 +297,14 @@ class Scaffold extends Object {
if(!empty($isDataBaseSet)) if(!empty($isDataBaseSet))
{ {
$this->controllerClass->constructClasses(); $this->controllerClass->constructClasses();
if(!defined('AUTO_SESSION') || AUTO_SESSION == true)
{
session_write_close();
$session =& CakeSession::getInstance();
}
if($params['action'] === 'index' || $params['action'] === 'list' || if($params['action'] === 'index' || $params['action'] === 'list' ||
$params['action'] === 'show' || $params['action'] === 'new' || $params['action'] === 'show' || $params['action'] === 'add' ||
$params['action'] === 'create' || $params['action'] === 'edit' || $params['action'] === 'create' || $params['action'] === 'edit' ||
$params['action'] === 'update' || $params['action'] === 'destroy') $params['action'] === 'update' || $params['action'] === 'destroy')
{ {
@ -317,7 +322,7 @@ class Scaffold extends Object {
$this->_scaffoldList($params); $this->_scaffoldList($params);
break; break;
case 'new': case 'add':
$this->_scaffoldNew($params); $this->_scaffoldNew($params);
break; break;

View file

@ -93,7 +93,7 @@
</table> </table>
<ul class="actions"> <ul class="actions">
<li><?php echo $html->linkTo('New '.$humanSingularName, '/'.$this->viewPath.'/new'); ?></li> <li><?php echo $html->linkTo('New '.$humanSingularName, '/'.$this->viewPath.'/add'); ?></li>
</ul> </ul>

View file

@ -81,7 +81,7 @@
echo "<li>".$html->linkTo('Edit '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/edit/'.$data[$objModel->tableToModel[$objModel->table]]['id'])."</li>"; echo "<li>".$html->linkTo('Edit '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/edit/'.$data[$objModel->tableToModel[$objModel->table]]['id'])."</li>";
echo "<li>".$html->linkTo('Delete '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/destroy/'.$data[$objModel->tableToModel[$objModel->table]]['id'])."</li>"; echo "<li>".$html->linkTo('Delete '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/destroy/'.$data[$objModel->tableToModel[$objModel->table]]['id'])."</li>";
echo "<li>".$html->linkTo('List '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/list')."</li>"; echo "<li>".$html->linkTo('List '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/list')."</li>";
echo "<li>".$html->linkTo('New '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/new')."</li>"; echo "<li>".$html->linkTo('New '.Inflector::humanize($objModel->name), '/'.$this->viewPath.'/add')."</li>";
foreach( $fieldNames as $field => $value ) { foreach( $fieldNames as $field => $value ) {
if( isset( $value['foreignKey'] ) ) if( isset( $value['foreignKey'] ) )
{ {
@ -181,7 +181,7 @@
<?php <?php
// add a link to create a new relation. // add a link to create a new relation.
echo "<li>".$html->linkTo('New '.Inflector::humanize($otherModelName),"/".Inflector::underscore($controller)."/new/")."</li>"; echo "<li>".$html->linkTo('New '.Inflector::humanize($otherModelName),"/".Inflector::underscore($controller)."/add/")."</li>";
// echo "<li>".$html->linkTo( "View ".Inflector::humanize($table), "/".Inflector::underscore($table)."/list/".$modelName."/".$data[$modelName]['id'])."</li>"; // echo "<li>".$html->linkTo( "View ".Inflector::humanize($table), "/".Inflector::underscore($table)."/list/".$modelName."/".$data[$modelName]['id'])."</li>";
?> ?>
</ul></div> </ul></div>

View file

@ -1280,7 +1280,25 @@ class Model extends Object
*/ */
function findBySql ($sql) function findBySql ($sql)
{ {
return $this->db->all($sql); $data = $this->db->all($sql);
foreach ($data as $key => $value)
{
foreach ($this->tableToModel as $key1 => $value1)
{
if (isset($data[$key][Inflector::singularize($key1)]))
{
$newData[$key][$value1] = $data[$key][Inflector::singularize($key1)];
}
}
}
if (!empty($newData))
{
return $newData;
}
else
{
return $data;
}
} }
/** /**

View file

@ -130,26 +130,32 @@ class Router extends Object {
'/:controller/:action/* (default)', '/:controller/:action/* (default)',
'/^(?:\/(?:([a-zA-Z0-9_\\-\\.]+)(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\\/(.*))?)?))[\\/]*$/', '/^(?:\/(?:([a-zA-Z0-9_\\-\\.]+)(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\\/(.*))?)?))[\\/]*$/',
array('controller', 'action'), array('controller', 'action'),
array() array());
);
$admin_route = array if(defined('CAKE_ADMIN'))
{
$admin = CAKE_ADMIN;
if(!empty($admin))
{
$this->routes[] = array
( (
'/:controller/:admin/:action/* (default)', '/:'.$admin.'/:controller/:action/* (default)',
'/^(?:\/(?:([a-zA-Z0-9_\\-\\.]+)(?:\\/(admin)(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\/(.*))?)?)?))[\/]*$/', '/^(?:\/(?:('.$admin.')(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\\/([a-zA-Z0-9_\\-\\.]+)(?:\/(.*))?)?)?))[\/]*$/',
array('controller', 'admin', 'action'), array($admin, 'controller', 'action'),
array() array());
);
}
}
$this->connect('/bare/:controller/:action/*', array('bare'=>'1')); $this->connect('/bare/:controller/:action/*', array('bare'=>'1'));
$this->connect('/ajax/:controller/:action/*', array('bare'=>'1')); $this->connect('/ajax/:controller/:action/*', array('bare'=>'1'));
$this->routes[] = $admin_route;
$this->routes[] = $default_route; $this->routes[] = $default_route;
foreach ($this->routes as $route) foreach ($this->routes as $route)
{ {
list($route, $regexp, $names, $defaults) = $route; list($route, $regexp, $names, $defaults) = $route;
if (preg_match($regexp, $url, $r)) if (preg_match($regexp, $url, $r))
{ {
// $this->log($url.' matched '.$regexp, 'note'); // $this->log($url.' matched '.$regexp, 'note');

View file

@ -54,11 +54,11 @@ class Security extends Object
function inactiveMins() function inactiveMins()
{ {
//$security = Security::getInstance(); $security =& Security::getInstance();
switch (CAKE_SECURITY) switch (CAKE_SECURITY)
{ {
case 'high': case 'high':
return; return 0;
break; break;
case 'medium': case 'medium':
return ; return ;

View file

@ -45,7 +45,7 @@ view file, a user-customizable error page for handling missing/invalid views dur
<p> <p>
<strong>Fatal</strong>: Unable to load view file <em><?php echo $this->missingView;?></em> for <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> action <em><?php echo $this->missingView;?>::<?php echo $this->params['action'];?></em>
</p> </p>
<?php if (DEBUG>1):?> <?php if (DEBUG>1):?>