Hi ppl!
I discovered that it is possible to pass functions defined in the
controller to the view. However I must prefix the $this->set()
statement with an @ symbol or else PHP claims that there's and
undefined constant in the view at the line you try to call it. For
example I define my title formatting function in the controller to
keep the view clean as possible:
--
function some_action()
{
// ... some code here ...
// function for title formatting
function tf($s)
{
$ret = "";
$s = str_replace("_", " ", $s);
for ($i = 0; $i < strlen($s); $i++)
{
$ucase = false;
if ($i == 0)
$ucase = true;
else
if ($s[$i-1] == " " or $s[$i-1] == "-")
$ucase = true;
$ret .= $ucase ? strtoupper($s[$i]) : $s[$i];
}
return $ret;
}
// ... some more code ...
@$this->set("tf", tf);
}
---
I need this because in an image gallery gallery names come from folder
names and so I need to convert strings like "jean-paul_belmondo" to
"Jean-Paul Belmondo" to display it to the user. So in the view I use
the tf() function like tf($gallery_name). Nevertheless I must suppress
the output of $this->set() or else I got an undefined constant notice.
I wonder why PHP sends a notice when otherwise the function is
functioning. :)
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---