Merging [920] [922] [929]

[920]
Small bugfix for after condition in AjaxHelper::remoteFunction

[922]
Fixed Ticket #224
Added patch from Ticket #221
Added patch from Ticket #222
Renamed renderMethod() to requestAction() the name fits better since we are really requesting another objects response.
Added a default setting to turn of autoRender for the class you are requesting the action from, 
this will allow you to request an action and use the return how you like, instead of letting the object output the content
directly to the browser if it would normally do so.

[929]
Adding fix for Itcket #225.

Moved code for beforeFilters to first section of Controller::constructClasses().
Removed current implementaion of  beforeFilters. This will be changed to pass
a reference of the object to the filters through a core filters class.
The core filter class will then load the filters and perform all request on the object in the order the
filters are arranged in var $beforeFilters, each beforeFilter needs to be a class that the core filter class will create
an instance of. If one of the filters fails, it will return the object, untouched and not try to process other filters, an 
failed var will be set on the controller.

This will be done before data base is initialized for the current object that is being filtered.

Modifed the requestAction() changes are noted below

        Using inside of a controller.
        Default
        $this->requestAction('/controller/action/argument/');
        Request Object to render output directly
        $this->requestAction('/controller/action/argument/', a('render'));

        Using a helper object to make request inside of a view:
        Default
        $helpername->requestAction('/controller/action/argument/');
        Request Object to render output directly
        $helpername->requestAction('/controller/action/argument/', a('render'));

        Using the View object "$this" in a view to make request:
        $this->requestAction('/controller/action/argument/');
        Request Object to render output directly
        $this->requestAction('/controller/action/argument/', a('render'));




git-svn-id: https://svn.cakephp.org/repo/trunk/cake@930 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-09-21 05:48:09 +00:00
parent b31a699d3e
commit 3fb93807a9
9 changed files with 53 additions and 58 deletions

View file

@ -211,7 +211,22 @@ class Controller extends Object
* *
*/ */
function constructClasses(){ function constructClasses(){
if (!empty($this->beforeFilter))
{
if(is_array($this->beforeFilter))
{
foreach($this->beforeFilter as $filter)
{
}
}
else
{
}
}
if(empty($this->params['pass'])) if(empty($this->params['pass']))
{ {
$id = false; $id = false;
@ -255,27 +270,6 @@ class Controller extends Object
} }
} }
} }
if (!empty($this->beforeFilter))
{
if(is_array($this->beforeFilter))
{
foreach($this->beforeFilter as $filter)
{
if(is_callable(array($this,$filter)))
{
$this->$filter();
}
}
}
else
{
if(is_callable(array($this,$this->beforeFilter)))
{
$this->{$this->beforeFilter}();
}
}
}
} }
/** /**

View file

@ -79,6 +79,12 @@ class Dispatcher extends Object
$missingController = false; $missingController = false;
$missingAction = false; $missingAction = false;
$missingView = false; $missingView = false;
if(!in_array('render', array_keys($params)))
{
$params['render'] = 0;
}
if (empty($params['controller'])) if (empty($params['controller']))
{ {
@ -129,6 +135,7 @@ class Dispatcher extends Object
$controller->passed_args = empty($params['pass'])? null: $params['pass']; $controller->passed_args = empty($params['pass'])? null: $params['pass'];
$controller->viewpath = Inflector::underscore($ctrlName); $controller->viewpath = Inflector::underscore($ctrlName);
$controller->autoLayout = !$params['bare']; $controller->autoLayout = !$params['bare'];
$controller->autoRender = !$params['render'];
if((in_array('scaffold', array_keys($classVars))) && ($missingAction === true)) if((in_array('scaffold', array_keys($classVars))) && ($missingAction === true))
{ {
@ -197,6 +204,7 @@ class Dispatcher extends Object
$params['form'][$name] = $data; $params['form'][$name] = $data;
} }
$params['bare'] = empty($params['ajax'])? (empty($params['bare'])? 0: 1): 1; $params['bare'] = empty($params['ajax'])? (empty($params['bare'])? 0: 1): 1;
return $params; return $params;
} }

View file

@ -129,22 +129,6 @@ class Helper extends Object
$this->tags[$keyName]); $this->tags[$keyName]);
} }
/**
*
* Allow calling a controllers method from a helper
*
*
* @param unknown_type $url
* @param unknown_type $extra
* @return unknown
*/
function renderMethod ($url, $extra = false)
{
$dispatcher = new Dispatcher();
return $dispatcher->dispatch($url, array('bare'=>1));
}
function readConfigFile ($fileName) function readConfigFile ($fileName)
{ {
$fileLineArray = file($fileName); $fileLineArray = file($fileName);

View file

@ -158,7 +158,7 @@ class AjaxHelper extends Helper
} }
if (isset($options['after'])) if (isset($options['after']))
{ {
$func = "$func; {$options['before']};"; $func = "$func; {$options['after']};";
} }
if (isset($options['condition'])) if (isset($options['condition']))
{ {

View file

@ -503,10 +503,10 @@ class HtmlHelper extends Helper
$out = array(); $out = array();
foreach ($names as $arg) foreach ($names as $arg)
{ {
$out[] = sprintf($this->tags['tableHeader'], $this->parseHtmlOptions($th_options), $arg); $out[] = sprintf($this->tags['tableheader'], $this->parseHtmlOptions($th_options), $arg);
} }
return sprintf($this->tags['tableHeader'], $this->parseHtmlOptions($tr_options), join(' ', $out)); return sprintf($this->tags['tableheader'], $this->parseHtmlOptions($tr_options), join(' ', $out));
} }
@ -1239,8 +1239,8 @@ class HtmlHelper extends Helper
function dayOptionTag( $tagName, $value=null, $selected=null, $optionAttr=null) function dayOptionTag( $tagName, $value=null, $selected=null, $optionAttr=null)
{ {
$value = isset($value)? $value : $this->tagValue($tagName); $value = isset($value)? $value : $this->tagValue($tagName."_day");
$dayValue = empty($value) ? date('d') : date('d',strtotime( $value ) ); $dayValue = empty($value) ? date('d') : $value;
$days=array('1'=>'1','2'=>'2','3'=>'3','4'=>'4', $days=array('1'=>'1','2'=>'2','3'=>'3','4'=>'4',
'5'=>'5','6'=>'6','7'=>'7','8'=>'8','9'=>'9', '5'=>'5','6'=>'6','7'=>'7','8'=>'8','9'=>'9',
'10'=>'10','11'=>'11','12'=>'12', '10'=>'10','11'=>'11','12'=>'12',
@ -1257,9 +1257,9 @@ class HtmlHelper extends Helper
function yearOptionTag( $tagName, $value=null, $minYear=null, $maxYear=null, $selected=null, $optionAttr=null) function yearOptionTag( $tagName, $value=null, $minYear=null, $maxYear=null, $selected=null, $optionAttr=null)
{ {
$value = isset($value)? $value : $this->tagValue($tagName); $value = isset($value)? $value : $this->tagValue($tagName."_year");
$yearValue = empty($value) ? date('Y') : date('Y',strtotime( $value ) ); $yearValue = empty($value) ? date('Y') : $value;
$maxYear = is_null($maxYear) ? $yearValue + 10 : $maxYear; $maxYear = is_null($maxYear) ? $yearValue + 10 : $maxYear;
@ -1286,8 +1286,8 @@ class HtmlHelper extends Helper
function monthOptionTag( $tagName, $value=null, $selected=null, $optionAttr=null) function monthOptionTag( $tagName, $value=null, $selected=null, $optionAttr=null)
{ {
$value = isset($value)? $value : $this->tagValue($tagName); $value = isset($value)? $value : $this->tagValue($tagName."_month");
$monthValue = empty($value) ? date('m') : date('m',strtotime( $value ) ); $monthValue = empty($value) ? date('m') : $value ;
$months=array('1'=>'January','2'=>'February','3'=>'March', $months=array('1'=>'January','2'=>'February','3'=>'March',
'4'=>'April','5'=>'May','6'=>'June','7'=>'July','8'=>'August', '4'=>'April','5'=>'May','6'=>'June','7'=>'July','8'=>'August',
'9'=>'September','10'=>'October','11'=>'November','12'=>'December'); '9'=>'September','10'=>'October','11'=>'November','12'=>'December');
@ -1301,14 +1301,14 @@ class HtmlHelper extends Helper
$selected=null, $selected=null,
$optionAttr=null ) $optionAttr=null )
{ {
$value = isset($value)? $value : $this->tagValue($tagName); $value = isset($value)? $value : $this->tagValue($tagName."_hour");
if ( $format24Hours ) if ( $format24Hours )
{ {
$hourValue = empty($value) ? date('H') : date('H',strtotime( $value ) ); $hourValue = empty($value) ? date('H') : $value;
} }
else else
{ {
$hourValue = empty($value) ? date('g') : date('g',strtotime( $value ) ); $hourValue = empty($value) ? date('g') : $value;
} }
if ( $format24Hours ) if ( $format24Hours )
{ $hours = array('0'=>'00','1'=>'01','2'=>'02','3'=>'03','4'=>'04', { $hours = array('0'=>'00','1'=>'01','2'=>'02','3'=>'03','4'=>'04',
@ -1333,8 +1333,8 @@ class HtmlHelper extends Helper
function minuteOptionTag( $tagName, $value=null, $selected=null, $optionAttr=null) function minuteOptionTag( $tagName, $value=null, $selected=null, $optionAttr=null)
{ {
$value = isset($value)? $value : $this->tagValue($tagName); $value = isset($value)? $value : $this->tagValue($tagName."_min");
$minValue = empty($value) ? date('i') : date('i',strtotime( $value ) ); $minValue = empty($value) ? date('i') : $value ;
for( $minCount=0; $minCount<61; $minCount++) for( $minCount=0; $minCount<61; $minCount++)
{ {
$mins[$minCount] = sprintf('%02d', $minCount); $mins[$minCount] = sprintf('%02d', $minCount);
@ -1347,8 +1347,8 @@ class HtmlHelper extends Helper
function meridianOptionTag( $tagName, $value=null, $selected=null, $optionAttr=null) function meridianOptionTag( $tagName, $value=null, $selected=null, $optionAttr=null)
{ {
$value = isset($value)? $value : $this->tagValue($tagName); $value = isset($value)? $value : $this->tagValue($tagName."_meridian");
$merValue = empty($value) ? date('a') : date('a',strtotime( $value ) ); $merValue = empty($value) ? date('a') : $value ;
$meridians = array('am'=>'am','pm'=>'pm'); $meridians = array('am'=>'am','pm'=>'pm');
$option = $this->selectTag($tagName.'_meridian', $meridians, $merValue, $option = $this->selectTag($tagName.'_meridian', $meridians, $merValue,
@ -1379,7 +1379,7 @@ class HtmlHelper extends Helper
switch ($timeFormat) switch ($timeFormat)
{ {
case '24': case '24':
$opt .= $this->hourOptionTag( $tagName, true ) . ':' . $this->minuteOptionTag( $tagName ); $opt .= $this->hourOptionTag( $tagName, null , true ) . ':' . $this->minuteOptionTag( $tagName );
break; break;
case '12': case '12':
$opt .= $this->hourOptionTag( $tagName ) . ':' . $this->minuteOptionTag( $tagName ) . ' ' . $this->meridianOptionTag($tagName); $opt .= $this->hourOptionTag( $tagName ) . ':' . $this->minuteOptionTag( $tagName ) . ' ' . $this->meridianOptionTag($tagName);
@ -1395,4 +1395,4 @@ class HtmlHelper extends Helper
} }
} }
?> ?>

View file

@ -535,7 +535,7 @@ class Model extends Object
function _constructAssociatedModels($modelName, $type, $settings = false) function _constructAssociatedModels($modelName, $type, $settings = false)
{ {
$modelName = Inflector::singularize($modelName); $modelName = Inflector::singularize($modelName);
$collectionKey = strtolower($modelName); $collectionKey = Inflector::underscore($modelName);
switch($type) switch($type)
{ {

View file

@ -104,8 +104,16 @@ class Object
* @param unknown_type $extra * @param unknown_type $extra
* @return unknown * @return unknown
*/ */
function renderMethod ($url, $extra = array()) function requestAction ($url, $extra = array())
{ {
if(in_array('render', $extra))
{
$extra['render'] = 0;
}
else
{
$extra['render'] = 1;
}
$extra = array_merge($extra, array('bare'=>1)); $extra = array_merge($extra, array('bare'=>1));
$dispatcher =& new Dispatcher(); $dispatcher =& new Dispatcher();
return $dispatcher->dispatch($url, $extra); return $dispatcher->dispatch($url, $extra);

View file

@ -194,7 +194,7 @@ class Scaffold extends Object {
function _scaffoldCreate($params) function _scaffoldCreate($params)
{ {
$this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames() ); $this->controllerClass->set('fieldNames', $this->controllerClass->generateFieldNames() );
$this->cleanUpFields(); $this->_cleanUpFields();
if ($this->controllerClass->models[$this->modelKey]->save($this->controllerClass->params['data'])) if ($this->controllerClass->models[$this->modelKey]->save($this->controllerClass->params['data']))
{ {

View file

@ -438,6 +438,7 @@ class View extends Object
function missingView() function missingView()
{ {
//We are simulating action call below, this is not a filename! //We are simulating action call below, this is not a filename!
$this->autoLayout = true;
$this->missingView = $this->name; $this->missingView = $this->name;
$this->render('../errors/missingView'); $this->render('../errors/missingView');
} }