Some changes to allow calling a method from another controller in the view.

helpers can now use this like a url to get methods return value:
$helpername->renderMethod('/controller/action/param/');
Refactored dispatcher.
Adding bug fix by nate in [894] [896]
Added extra param View::renderMethod()
Fixed bug related to #72, #111, #113, #209
Some of those tickets where closed as duplicates already

git-svn-id: https://svn.cakephp.org/repo/trunk/cake@900 3807eeeb-6ff5-0310-8944-8be069107fe0
This commit is contained in:
phpnut 2005-09-19 01:16:05 +00:00
parent 1a93ab942f
commit 5f1d672d5e
4 changed files with 23 additions and 9 deletions

View file

@ -129,6 +129,22 @@ class Helper extends Object
$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)
{
$fileLineArray = file($fileName);

View file

@ -39,6 +39,7 @@
* @subpackage cake.libs.helpers
* @since CakePHP v 0.9.2
*/
class JavascriptHelper extends Helper
{
/**
@ -53,14 +54,15 @@ class JavascriptHelper extends Helper
}
/**
* Returns a JavaScript include tag (LINK element)
* Returns a JavaScript include tag (SCRIPT element)
*
* @param string $url URL to JavaScript file.
* @return string
*/
function link($url)
{
return sprintf($this->tags['javascriptlink'], $this->base.$url);
if(strpos($url, ".") === false) $url .= ".js";
return sprintf($this->tags['javascriptlink'], $this->base . JS_URL . $url);
}
/**
@ -71,6 +73,7 @@ class JavascriptHelper extends Helper
*/
function linkOut($url)
{
if(strpos($url, ".") === false) $url .= ".js";
return sprintf($this->tags['javascriptlink'], $url);
}

View file

@ -1270,8 +1270,8 @@ class Model extends Object
$joins = count($joins)? join(' ', $joins): null;
$whers = count($whers)? '('.join(' AND ', $whers).')': null;
$conditions .= ($conditions && $whers? ' AND ': null).$whers;
$offset = $page > 1? $page*$limit: 0;
$offset = $page > 1? ($page-1) * $limit: 0;
$limit_str = $limit
? $this->db->selectLimit($limit, $offset)

View file

@ -553,11 +553,6 @@ class View extends Object
return $out;
}
function fetch ($url)
{
$dispatcher = new Dispatcher();
return $dispatcher->dispatch($url, array('bare'=>1));
}
}
?>