总是被调用的 PHP 方法
我目前正在开发自己的 PHP-MVC 框架(仅用于体验目的)。
我的问题:是否可以在每次类方法时调用定义的函数或方法 已被调用?
例如:
public function view($id) {
//Code ...
$this->view->render(__FUNCTION__);
}
我想要的是:
public function view($id) {
//Code ...
//render-method is called automatically with functionname as parameter
}
我尝试了不同的方法......但没有成功。 如果有人能帮助我解决这个问题那就太好了。
干杯, 克里斯
I'm currently working on an own PHP-MVC-Framework (for experience purposes only).
My question: Is it possible to call a defined function or method, every time a class-method
has been called?
For example:
public function view($id) {
//Code ...
$this->view->render(__FUNCTION__);
}
What I want is:
public function view($id) {
//Code ...
//render-method is called automatically with functionname as parameter
}
I tried different methods ... but without success.
Would be great if someone could help me out with this.
Cheers,
Chris
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 MagicMethods 来实现此行为:
记住:视图函数必须是私有的/受保护的。
应该执行 ::__call(),然后执行 ::view() 方法
You can use Magic Methods do achieve this behavior:
Remember: view function must be private/protected.
Should do ::__call(), then ::view() method
您可以使用 PHP 使用变量值来执行的能力来创建一个函数作为联络人。例如:
You could create a function as a liaison using PHP's ability to use variable values for execution purposes. for example:
您可以使用包装方法。调用此方法并将其他所有内容作为参数传递。
You can use a wrapper method. Call this method and pass everything else as a parameters.