2005-06-19 23:30:36 +00:00
|
|
|
<?PHP
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
// + $Id$
|
|
|
|
// +------------------------------------------------------------------+ //
|
|
|
|
// + Cake <https://developers.nextco.com/cake/> + //
|
|
|
|
// + Copyright: (c) 2005, Cake Authors/Developers + //
|
|
|
|
// + Author(s): Michal Tatarynowicz aka Pies <tatarynowicz@gmail.com> + //
|
|
|
|
// + Larry E. Masters aka PhpNut <nut@phpnut.com> + //
|
|
|
|
// + Kamil Dzielinski aka Brego <brego.dk@gmail.com> + //
|
|
|
|
// +------------------------------------------------------------------+ //
|
|
|
|
// + Licensed under The MIT License + //
|
|
|
|
// + Redistributions of files must retain the above copyright notice. + //
|
|
|
|
// + See: http://www.opensource.org/licenses/mit-license.php + //
|
|
|
|
//////////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Purpose: Controller
|
|
|
|
* Application controller (controllers are where you put all the actual code)
|
|
|
|
* Provides basic functionality, such as rendering views (aka displaying templates).
|
|
|
|
* Automatically selects model name from on singularized object class name
|
|
|
|
* and creates the model object if proper class exists.
|
|
|
|
*
|
|
|
|
* @filesource
|
|
|
|
* @author Cake Authors/Developers
|
|
|
|
* @copyright Copyright (c) 2005, Cake Authors/Developers
|
|
|
|
* @link https://developers.nextco.com/cake/wiki/Authors Authors/Developers
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.libs
|
|
|
|
* @since Cake v 0.2.9
|
|
|
|
* @version $Revision$
|
|
|
|
* @modifiedby $LastChangedBy$
|
|
|
|
* @lastmodified $Date$
|
|
|
|
* @license http://www.opensource.org/licenses/mit-license.php The MIT License
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*/
|
|
|
|
uses('model', 'template', 'inflector', 'folder');
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @package cake
|
|
|
|
* @subpackage cake.libs
|
|
|
|
* @since Cake v 0.2.9
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
class Controller extends Template
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* Name of the controller.
|
|
|
|
*
|
|
|
|
* @var unknown_type
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $name = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Stores the current URL (for links etc.)
|
|
|
|
*
|
|
|
|
* @var string Current URL
|
|
|
|
*/
|
|
|
|
var $here = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @var unknown_type
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $parent = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Action to be performed.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
* @access public
|
|
|
|
*/
|
|
|
|
var $action = null;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* An array of names of models the particular controller wants to use.
|
|
|
|
*
|
|
|
|
* @var mixed A single name as a string or a list of names as an array.
|
2005-06-21 23:44:49 +00:00
|
|
|
* @access protected
|
2005-06-19 23:30:36 +00:00
|
|
|
*/
|
|
|
|
var $uses = false;
|
|
|
|
|
2005-06-21 23:44:49 +00:00
|
|
|
/**
|
|
|
|
* An array of names of built-in helpers to include.
|
|
|
|
*
|
|
|
|
* @var mixed A single name as a string or a list of names as an array.
|
|
|
|
* @access protected
|
|
|
|
*/
|
|
|
|
var $helpers = array('html');
|
|
|
|
|
2005-06-19 23:30:36 +00:00
|
|
|
/**
|
|
|
|
* Constructor.
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function __construct ($params=null)
|
|
|
|
{
|
2005-06-22 23:16:26 +00:00
|
|
|
parent::__construct();
|
|
|
|
|
2005-06-19 23:30:36 +00:00
|
|
|
$this->params = $params;
|
|
|
|
|
|
|
|
$r = null;
|
|
|
|
if (!preg_match('/(.*)Controller/i', get_class($this), $r))
|
2005-06-21 23:44:49 +00:00
|
|
|
{
|
|
|
|
die("Controller::__construct() : Can't get or parse my own class name, exiting.");
|
|
|
|
}
|
2005-06-19 23:30:36 +00:00
|
|
|
|
|
|
|
$this->name = strtolower($r[1]);
|
|
|
|
$this->viewpath = Inflector::underscore($r[1]);
|
|
|
|
|
|
|
|
$model_class = Inflector::singularize($this->name);
|
|
|
|
|
2005-06-23 13:59:02 +00:00
|
|
|
//Is this needed?
|
2005-06-23 20:41:10 +00:00
|
|
|
$this->db = DboFactory::getInstance();
|
2005-06-23 13:59:02 +00:00
|
|
|
|
|
|
|
if (class_exists($model_class) && ($this->uses === false))
|
2005-06-19 23:30:36 +00:00
|
|
|
{
|
2005-06-23 13:59:02 +00:00
|
|
|
$this->$model_class = new $model_class();
|
2005-06-19 23:30:36 +00:00
|
|
|
}
|
|
|
|
elseif ($this->uses)
|
|
|
|
{
|
|
|
|
if (!$this->db)
|
2005-06-23 13:59:02 +00:00
|
|
|
{
|
|
|
|
die("Controller::__construct() : ".$this->name." controller needs database access, exiting.");
|
|
|
|
}
|
2005-06-19 23:30:36 +00:00
|
|
|
|
|
|
|
$uses = is_array($this->uses)? $this->uses: array($this->uses);
|
|
|
|
|
|
|
|
foreach ($uses as $model_name)
|
|
|
|
{
|
|
|
|
$model_class = ucfirst(strtolower($model_name));
|
|
|
|
|
|
|
|
if (class_exists($model_class))
|
|
|
|
{
|
|
|
|
$this->$model_name = new $model_class (false);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
die("Controller::__construct() : ".ucfirst($this->name)." requires missing model {$model_class}, exiting.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2005-06-21 23:44:49 +00:00
|
|
|
function missingController()
|
2005-06-19 23:30:36 +00:00
|
|
|
{
|
2005-06-23 08:32:04 +00:00
|
|
|
//We are simulating action call below, this is not a filename!
|
|
|
|
$this->render('../errors/missingController');
|
2005-06-19 23:30:36 +00:00
|
|
|
}
|
|
|
|
|
2005-06-21 23:44:49 +00:00
|
|
|
function missingAction()
|
2005-06-19 23:30:36 +00:00
|
|
|
{
|
2005-06-23 08:32:04 +00:00
|
|
|
//We are simulating action call below, this is not a filename!
|
|
|
|
$this->render('../errors/missingAction');
|
2005-06-19 23:30:36 +00:00
|
|
|
}
|
|
|
|
|
2005-06-21 23:44:49 +00:00
|
|
|
function missingView()
|
2005-06-19 23:30:36 +00:00
|
|
|
{
|
2005-06-23 08:32:04 +00:00
|
|
|
//We are simulating action call below, this is not a filename!
|
|
|
|
$this->render('../errors/missingView');
|
2005-06-19 23:30:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Redirects to given $url, after turning off $this->autoRender.
|
|
|
|
*
|
|
|
|
* @param unknown_type $url
|
|
|
|
*/
|
|
|
|
function redirect ($url)
|
|
|
|
{
|
|
|
|
$this->autoRender = false;
|
|
|
|
header ('Location: '.$this->base.$url);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Enter description here...
|
|
|
|
*
|
|
|
|
* @param unknown_type $action
|
|
|
|
*/
|
|
|
|
function setAction ($action)
|
|
|
|
{
|
|
|
|
$this->action = $action;
|
|
|
|
|
|
|
|
$args = func_get_args();
|
|
|
|
call_user_func_array(array(&$this, $action), $args);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Displays an error page to the user. Uses layouts/error.html to render the page.
|
|
|
|
*
|
|
|
|
* @param int $code Error code (for instance: 404)
|
|
|
|
* @param string $name Name of the error (for instance: Not Found)
|
|
|
|
* @param string $message Error message
|
|
|
|
*/
|
|
|
|
function error ($code, $name, $message)
|
|
|
|
{
|
|
|
|
header ("HTTP/1.0 {$code} {$name}");
|
|
|
|
print ($this->_render(VIEWS.'layouts/error.thtml', array('code'=>$code,'name'=>$name,'message'=>$message)));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2005-06-22 23:16:26 +00:00
|
|
|
?>
|