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');
/**
* 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.)
* 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 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');
if (class_exists('DATABASE_CONFIG'))

View file

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

View file

@ -54,6 +54,8 @@ class Session extends Object
/**
* Enter description here...
*
* Use like this. $this->session->write('Controller.sessKey', 'session value');
*
* @param unknown_type $name
* @param unknown_type $value
* @return unknown
@ -66,6 +68,8 @@ class Session extends Object
/**
* Enter description here...
*
* Use like this. $this->session->read('Controller.sessKey');
*
* @param unknown_type $name
* @return unknown
*/
@ -77,6 +81,8 @@ class Session extends Object
/**
* Enter description here...
*
* Use like this. $this->session->del('Controller.sessKey');
*
* @param unknown_type $name
* @return unknown
*/
@ -88,6 +94,8 @@ class Session extends Object
/**
* Enter description here...
*
* Use like this. $this->session->check('Controller.sessKey');
*
* @param unknown_type $name
* @return unknown
*/
@ -112,9 +120,9 @@ class Session extends Object
* @param unknown_type $name
* @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))
{
$this->controllerClass->constructClasses();
if(!defined('AUTO_SESSION') || AUTO_SESSION == true)
{
session_write_close();
$session =& CakeSession::getInstance();
}
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'] === 'update' || $params['action'] === 'destroy')
{
@ -317,7 +322,7 @@ class Scaffold extends Object {
$this->_scaffoldList($params);
break;
case 'new':
case 'add':
$this->_scaffoldNew($params);
break;

View file

@ -93,7 +93,7 @@
</table>
<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>

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('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('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 ) {
if( isset( $value['foreignKey'] ) )
{
@ -181,7 +181,7 @@
<?php
// 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>";
?>
</ul></div>

View file

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

View file

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

View file

@ -166,7 +166,7 @@ class HtmlHelper extends Helper
{
$output = $this->base.'/'.strtolower($this->params['controller']).'/'.$url;
}
return $this->output(preg_replace('/&([^a])/', '&amp;\1', $output), $return);
}

View file

@ -45,7 +45,7 @@ view file, a user-customizable error page for handling missing/invalid views dur
<p>
<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>
<?php if (DEBUG>1):?>