From 27d16ff9b915b06df128da85f705edadb6956097 Mon Sep 17 00:00:00 2001 From: pies Date: Wed, 22 Jun 2005 23:16:26 +0000 Subject: [PATCH] I'm sorry, I've reversed two changes. I've changed the error views names to underscored, and I've changed the default DEBUG to 1. The first one is for consistency (no UppperCase filenames, please), the second is because while I'm no enemy of application security, the application has to be safe _after_ it's written, not before. And to easily write an application, the developer should have the DEBUG mode set to 1 or 2. Other than that, I think it's a very good idea to put the tag generators in helpers :) git-svn-id: https://svn.cakephp.org/repo/trunk/cake@271 3807eeeb-6ff5-0310-8944-8be069107fe0 --- config/core.php | 2 +- config/paths.php | 328 ++++++++++++++++++++--------------------- libs/controller.php | 12 +- libs/dbo/dbo_mysql.php | 2 +- libs/model.php | 19 +-- libs/object.php | 2 +- libs/template.php | 2 +- 7 files changed, 184 insertions(+), 183 deletions(-) diff --git a/config/core.php b/config/core.php index 39c881597..13b629c04 100644 --- a/config/core.php +++ b/config/core.php @@ -22,7 +22,7 @@ * - 1: development * - 2: full debug with sql */ -define ('DEBUG', 0); +define ('DEBUG', 1); /** * Compress output CSS (removing comments, whitespace, repeating tags etc.) diff --git a/config/paths.php b/config/paths.php index 0863f9d22..7fecf40d9 100644 --- a/config/paths.php +++ b/config/paths.php @@ -1,164 +1,164 @@ - + // -// + Copyright: (c) 2005, Cake Authors/Developers + // -// +------------------------------------------------------------------+ // -// + Licensed under The MIT License + // -////////////////////////////////////////////////////////////////////////// - -/** - * In this file you set paths to different directories used by Cake. - * - * @package cake - * @subpackage cake.config - */ - -/** - * If the index.php file is used instead of an .htaccess file - * or if the user can not set the web root to use the public - * directory we will define ROOT there, otherwise we set it - * here. - */ -if(!defined('ROOT')) -{ - define ('ROOT', '../'); -} - -/** - * Path to the application's directory. - */ -define ('APP', ROOT.'app'.DS); - -/** - * Path to the application's models directory. - */ -define ('MODELS', APP.'models'.DS); - -/** - * Path to the application's controllers directory. - */ -define ('CONTROLLERS', APP.'controllers'.DS); - -/** - * Path to the application's helpers directory. - */ -define ('HELPERS', APP.'helpers'.DS); - -/** - * Path to the application's views directory. - */ -define ('VIEWS', APP.'views'.DS); - -/** - * Path to the application's view's layouts directory. - */ -define ('LAYOUTS', APP.'views'.DS.'layouts'.DS); - -/** - * Path to the application's view's elements directory. - * It's supposed to hold pieces of PHP/HTML that are used on multiple pages - * and are not linked to a particular layout (like polls, footers and so on). - */ -define ('ELEMENTS', APP.'views'.DS.'elements'.DS); - -/** - * Path to the configuration files directory. - */ -define ('CONFIGS', ROOT.'config'.DS); - -/** - * Path to the libs directory. - */ -define ('LIBS', ROOT.'libs'.DS); - -/** - * Path to the logs directory. - */ -define ('LOGS', ROOT.'logs'.DS); - -/** - * Path to the modules directory. - */ -define ('MODULES', ROOT.'modules'.DS); - -/** - * Path to the public directory. - */ -define ('WWW_ROOT', ROOT.'public'.DS); - -/** - * Path to the public directory. - */ -define ('CSS', WWW_ROOT.'css'.DS); - -/** - * Path to the scripts direcotry. - */ -define('SCRIPTS', ROOT.'scripts'.DS); - -/** - * Path to the tests directory. - */ -define ('TESTS', ROOT.'tests'.DS); - -/** - * Path to the controller test directory. - */ -define ('CONTROLLER_TESTS',TESTS.'app'.DS.'controllers'.DS); - -/** - * Path to the helpers test directory. - */ -define ('HELPER_TESTS', TESTS.'app'.DS.'helpers'.DS); - -/** - * Path to the models' test directory. - */ -define ('MODEL_TESTS', TESTS.'app'.DS.'models'.DS); - -/** - * Path to the lib test directory. - */ -define ('LIB_TESTS', TESTS.'libs'.DS); - -/** - * Path to the temporary files directory. - */ -define ('TMP', ROOT.'tmp'.DS); - -/** - * Path to the cache files directory. It can be shared between hosts in a multi-server setup. - */ -define('CACHE', TMP.'cache'.DS); - -/** - * Path to the vendors directory. - */ -define ('VENDORS', ROOT.'vendors'.DS); - -/** - * Path to the Pear directory - * The purporse is to make it easy porting Pear libs into Cake - * without setting the include_path PHP variable. - */ -define ('PEAR', VENDORS.'Pear'.DS); - - -/** - * Full url prefix - */ -define('FULL_BASE_URL', 'http://'.$_SERVER['HTTP_HOST']); - -/** - * Web path to the public images directory. - */ -define ('IMAGES_URL', '/img/'); - -/** - * Web path to the CSS files directory. - */ -define ('CSS_URL', '/css/'); - -?> + + // +// + Copyright: (c) 2005, Cake Authors/Developers + // +// +------------------------------------------------------------------+ // +// + Licensed under The MIT License + // +////////////////////////////////////////////////////////////////////////// + +/** + * In this file you set paths to different directories used by Cake. + * + * @package cake + * @subpackage cake.config + */ + +/** + * If the index.php file is used instead of an .htaccess file + * or if the user can not set the web root to use the public + * directory we will define ROOT there, otherwise we set it + * here. + */ +if(!defined('ROOT')) +{ + define ('ROOT', '../'); +} + +/** + * Path to the application's directory. + */ +define ('APP', ROOT.'app'.DS); + +/** + * Path to the application's models directory. + */ +define ('MODELS', APP.'models'.DS); + +/** + * Path to the application's controllers directory. + */ +define ('CONTROLLERS', APP.'controllers'.DS); + +/** + * Path to the application's helpers directory. + */ +define ('HELPERS', APP.'helpers'.DS); + +/** + * Path to the application's views directory. + */ +define ('VIEWS', APP.'views'.DS); + +/** + * Path to the application's view's layouts directory. + */ +define ('LAYOUTS', APP.'views'.DS.'layouts'.DS); + +/** + * Path to the application's view's elements directory. + * It's supposed to hold pieces of PHP/HTML that are used on multiple pages + * and are not linked to a particular layout (like polls, footers and so on). + */ +define ('ELEMENTS', APP.'views'.DS.'elements'.DS); + +/** + * Path to the configuration files directory. + */ +define ('CONFIGS', ROOT.'config'.DS); + +/** + * Path to the libs directory. + */ +define ('LIBS', ROOT.'libs'.DS); + +/** + * Path to the logs directory. + */ +define ('LOGS', ROOT.'logs'.DS); + +/** + * Path to the modules directory. + */ +define ('MODULES', ROOT.'modules'.DS); + +/** + * Path to the public directory. + */ +define ('WWW_ROOT', ROOT.'public'.DS); + +/** + * Path to the public directory. + */ +define ('CSS', WWW_ROOT.'css'.DS); + +/** + * Path to the scripts direcotry. + */ +define('SCRIPTS', ROOT.'scripts'.DS); + +/** + * Path to the tests directory. + */ +define ('TESTS', ROOT.'tests'.DS); + +/** + * Path to the controller test directory. + */ +define ('CONTROLLER_TESTS',TESTS.'app'.DS.'controllers'.DS); + +/** + * Path to the helpers test directory. + */ +define ('HELPER_TESTS', TESTS.'app'.DS.'helpers'.DS); + +/** + * Path to the models' test directory. + */ +define ('MODEL_TESTS', TESTS.'app'.DS.'models'.DS); + +/** + * Path to the lib test directory. + */ +define ('LIB_TESTS', TESTS.'libs'.DS); + +/** + * Path to the temporary files directory. + */ +define ('TMP', ROOT.'tmp'.DS); + +/** + * Path to the cache files directory. It can be shared between hosts in a multi-server setup. + */ +define('CACHE', TMP.'cache'.DS); + +/** + * Path to the vendors directory. + */ +define ('VENDORS', ROOT.'vendors'.DS); + +/** + * Path to the Pear directory + * The purporse is to make it easy porting Pear libs into Cake + * without setting the include_path PHP variable. + */ +define ('PEAR', VENDORS.'Pear'.DS); + + +/** + * Full url prefix + */ +define('FULL_BASE_URL', 'http://'.$_SERVER['HTTP_HOST']); + +/** + * Web path to the public images directory. + */ +define ('IMAGES_URL', '/img/'); + +/** + * Web path to the CSS files directory. + */ +define ('CSS_URL', '/css/'); + +?> diff --git a/libs/controller.php b/libs/controller.php index 7f13a93cf..1bd2172cb 100644 --- a/libs/controller.php +++ b/libs/controller.php @@ -102,6 +102,8 @@ class Controller extends Template */ function __construct ($params=null) { + parent::__construct(); + $this->params = $params; $r = null; @@ -140,26 +142,24 @@ class Controller extends Template } } } - - parent::__construct(); } function missingController() { $this->autoRender = false; - $this->render('../errors/missingController'); + $this->render('../errors/missing_controller'); } function missingAction() { $this->autoRender = false; - $this->render('../errors/missingAction'); + $this->render('../errors/missing_action'); } function missingView() { $this->autoRender = false; - $this->render('../errors/missingView'); + $this->render('../errors/missing_view'); } /** @@ -201,4 +201,4 @@ class Controller extends Template } -?> \ No newline at end of file +?> diff --git a/libs/dbo/dbo_mysql.php b/libs/dbo/dbo_mysql.php index e581ecca9..1cb7d3f0e 100644 --- a/libs/dbo/dbo_mysql.php +++ b/libs/dbo/dbo_mysql.php @@ -200,7 +200,7 @@ class DBO_MySQL extends DBO */ function selectLimit ($limit, $offset=null) { - return " LIMIT {$limit}".($offset? "{$offset}": null); + return $limit? " LIMIT {$limit}".($offset? "{$offset}": null): null; } } diff --git a/libs/model.php b/libs/model.php index 6c30d5e83..9cfb37c57 100644 --- a/libs/model.php +++ b/libs/model.php @@ -333,12 +333,12 @@ class Model extends Object * @param string $conditions SQL conditions (defaults to NULL) * @return field contents */ - function field ($name, $conditions=null) + function field ($name, $conditions=null, $order=null) { if ($conditions) { $conditions = $this->parseConditions($conditions); - $data = $this->find($conditions); + $data = $this->find($conditions, $name, $order); return $data[$name]; } elseif (isset($this->data[$name])) @@ -497,9 +497,9 @@ class Model extends Object * * @return boolean True if such a record exists */ - function hasAny ($sql_conditions = null) + function hasAny ($conditions = null) { - return $this->db->hasAny($this->table, $sql_conditions); + return $this->findCount($conditions); } @@ -508,11 +508,12 @@ class Model extends Object * * @param string $conditions SQL conditions * @param mixed $fields Either a single string of a field name, or an array of field names + * @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC") * @return array Array of records */ - function find ($conditions = null, $fields = null) + function find ($conditions = null, $fields = null, $order = null) { - $data = $this->findAll($conditions, $fields, null, 1); + $data = $this->findAll($conditions, $fields, $order, 1); return empty($data[0])? false: $data[0]; } @@ -546,7 +547,7 @@ class Model extends Object * * @param mixed $conditions SQL conditions as a string or as an array('field'=>'value',...) * @param mixed $fields Either a single string of a field name, or an array of field names - * @param string $order SQL ORDER BY conditions (e.g. "DESC" or "ASC") + * @param string $order SQL ORDER BY conditions (e.g. "price DESC" or "name ASC") * @param int $limit SQL LIMIT clause, for calculating items per page * @param int $page Page number * @return array Array of records @@ -613,8 +614,8 @@ class Model extends Object */ function findCount ($conditions) { - list($data) = $this->findAll($conditions, 'COUNT(id) AS count'); - return $data['count']; + list($data) = $this->findAll($conditions, 'COUNT(*) AS count'); + return isset($data['count'])? $data['count']: false; } /** diff --git a/libs/object.php b/libs/object.php index a95fe725a..70cfd3b74 100644 --- a/libs/object.php +++ b/libs/object.php @@ -33,7 +33,7 @@ uses('log'); /** - * Object class, allowing __construct and __destruct. + * Object class, allowing __construct and __destruct in PHP4. * * @package cake * @subpackage cake.libs diff --git a/libs/template.php b/libs/template.php index 2cb82fec8..7b9a348db 100644 --- a/libs/template.php +++ b/libs/template.php @@ -1290,4 +1290,4 @@ class Template extends Object } -?> \ No newline at end of file +?>