Use $ this-& gt; display () in file A to call the method of another class file. what should I do? File A: PHPcodeclassindexAction {publicfunctionindex () {echoabc; $ this-& gt; display (); is this line} use $ this-> display () in file () how can I call another class file method?
File:
PHP code
Class indexAction {public function index () {echo 'abc'; $ this-> display (); // this row }}
Class B files:
PHP code
Class view {public function display () {echo 'Template output succeeded ';}}
How can I instantiate A file so that $ this-> display () can call another Class B file
------ Solution --------------------
$ This-> display ()? This design is strange.
I'm afraid I have to inherit class indexAction extends view.
Alternatively, you can select the magic method _ call ()
Learn now:
PHP code
Class indexAction {// add a magic method public function _ call ($ mName, $ mArg) {$ view = new view (); if (method_exists ($ view, $ mName) call_user_func (array ($ view, $ mName ));}}