Hi all,
I am rather new to ZendFramework and am trying to figure this out. In my view script (index.phtml), I have this bit of code that says:
<?php
function getErrorString($element)
{
echo "<pre>";
print_r($this);
echo "</pre>";
$string = '';
if(!empty($this->error[$element]))
{
$string = $string.'<label class="error" for="'.$element.'" generated="true">';
foreach($this->error[$element] as $error)
{
$string = $string.$error;
}
$string = $string.'</label>';
}
return $string;
}
echo "<pre>";
print_r($this);
echo "</pre>";
getErrorString("blah");
die();
That gives me:
Fatal error: Using $this when not in object context in index.phtml on line XX
It seems to me that when you create a function within a view, you lose the $this variable. I did search around the net, and I can't see anyone else trying to achieve what I am doing (highly unlikely, maybe I'm searching it wrong).
With past experience developing other apps, I can't see a good reason why this function should be placed in a separate helper -> especially since this is the only place the function will ever be called.
Any ideas would be greatly appreciated.
Thanks!