在A文件中使用$this->display()调用另外一个类文件的方法,应该怎么做?
A文件:
- PHP code
<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->class indexAction{ public function index() { echo 'abc'; $this->display(); //就是这一行 }}
B类文件:
- PHP code
<!---ecms Code highlighting produced by Actipro CodeHighlighter (freeware)http://www.CodeHighlighter.com/-->class view { public function display() { echo '模板输出成功'; }}
要怎么实例化才能在A文件中可以这样$t
本文来源gaodai.ma#com搞##代!^码@网*
搞gaodaima代码
his->display()调用另外B类文件
——解决方案——————–
$this->display() ? 这种设计很奇怪
恐怕得靠继承吧 class indexAction extends view
或者可以选择魔术方法 __call()
现学现卖:
- PHP code
class indexAction{ //新增一个魔术方法 public function __call($mName, $mArg) { $view = new view(); if(method_exists($view, $mName)) call_user_func(array($view, $mName)); }}