public function processOutput($output)
{
if($this->hasEventHandler('onProcessOutput'))
{
$event=new COutputEvent($this,$output);
$this->onProcessOutput($event);
if(!$event->handled)
echo $output; // should echo $event->output
}
else
echo $output;
}
class MyProcessor extends COutputProcessor
{
public function init()
{
$this->onProcessOutput = array('TTest', 'lower');
$this->onProcessOutput = array('TTest', 'reverse');
parent::init();
}
}
class TTest
{
public function lower($event)
{
$event->output = strtolower($event->output);
}
public function reverse($event)
{
$event->output = strrev($event->output);
}
}
$this->beginWidget('MyProcessor');
echo 'This is just a Test';
$this->endWidget();
The doc is clear:
So if your event returns not true… the default is echoed…
Instead you need to echo your data and set handled to true to prevent default echo…
sorry, I dont get it
can you show me, how to output the lowered,reversed string using event handlers?
In this case you would need to assign only one function like
public function lowerreverse($event)
{
echo strrev(strtolower($event->output));
$event->handled = true;
}
or…
if you just want to use two methods… you need to handle the output in the last one… like
class TTest
{
public function lower($event)
{
$event->output = strtolower($event->output);
}
public function reverse($event)
{
$event->output = strrev($event->output);
echo $event->output;
$event->handled=true;
}
}
this works
but now I got a charset problem
[edit]
ok, it’s strtolower that causes problems