Hi there Yii,
I have a situation where I have to convert a certain string within a string to be renderPartial-ed.
For example:
// not actual code, just to represent the concept idea
$str = "The [%quick%] brown fox jumps over the [%lazy%] dog";
// I want it so that any string within [% %] is renderPartial-ed based on the string.
// In this case [%quick%] will be changed with the content of /site/quick.php
// and [%lazy%] will be changed with the content of /site/lazy.php
// but how?
// here is my code so far:
<?php
function test($m) {
return $this->renderPartial($m[1],array("data"=>$data));
}
$content = preg_replace_callback(
'#\[%(.+?)%\]#', 'test', $data['page']['content']);
?>
// this gives error:
// Fatal error: Using $this when not in object context in yadayada/protected/views/site/single.php on line 11
How can I achieve this?
Please help.