-
Hi everyone! This is my first post on the forum.
Could you help me with this question of object-oriented programming in PhalconPHP?
service.php
$compiler->addFunction('myfunction',function($resolvedArgs,$exprArgs) use ($compiler){
$arg = $compiler->expression($exprArgs[0]['expr']);
return 'ControllerBase::myfunction('.$arg.')';
});
ControllerBase.php
public static function myfunction($myString){
if ($this->session->has('mysession')) {
return $myString;
} else {
return 'session not found';
}
}
index.volt
<p>{{ myfunction('myString') }}<p>
Error message I'm getting:
Fatal error: Using $this when not in object context in ...app/controllers/ControllerBase.php
Error line: "if ($this->session->has('mysession')) {"
How to use the instance "$this->session" ( or any other method or property instantiated in ControllerBase.php ) in the function "$compiler->addFunction" ( service.php )?
-