How to call the code of another Controller in the TP framework Controller my website TP framework, a front-end D: \ WWW \ User \ Home \ Controller \ CommonController. class file, a background D: \ WWW \ snadmin \ Home \ ControllerCommonController. class file, I want to call the code in the background in the front-end file, do not know?
Front-end CommonController. class file code
CheckAdminSessiona (); // call the public function checkAdminSessiona () of the CommonController. class file in the background in this way. Is there any good way to call the public function checkAdminSessiona? }}}
Code of the CommonController. class file in the background
Public function checkAdminSessiona (){
If (! M ('aconfig')-> where (array ('date' => 0)-> find ()){
$ Tgbz_user = M ('tgbz')-> where (array ('zt '=> '0')-> select ();
$ Pipeits = 0;
Foreach ($ tgbz_user as $ val ){
$ Jsbz_list = tgbz_zd_cl ($ val ['id']);
Foreach ($ jsbz_list as $ val1 ){
If ($ val ['JB '] ==$ val1 ['JB'] & $ val ['user'] <> $ val1 ['user']) {
If (ppdd_add ($ val ['id'], $ val1 ['id']) {
$ Pipeits ++;
M ('tgbz')-> where (array ('id' => $ val ['id']) -> save (array ('CF _ DS' => '1 '));
Break;
}
}
}
}
}
}
Reply to discussion (solution)
Yes.
use Think\Controller;
Use method
Yes.
use Think\Controller;
Use method
Can you click here?
Yes.
use Think\Controller;
Use method
I have used it. I want to call the code of another CommonController. class controller file.
Non-static method: Called After instantiation
Static method: real-time direct static call
Non-static method: Called After instantiation
Static method: real-time direct static call
Static method: how to write code for real-time direct static call?
I didn't see the definition of static methods in your sample code
If there is a definition
\ Namespace \ class name: method name ()
I didn't see the definition of static methods in your sample code
If there is a definition
\ Namespace \ class name: method name ()
Background D: \ WWW \ snadmin \ Home \ ControllerCommonController. class file
Foreground D: \ WWW \ user \ Home \ ControllerCommonController. class file
Call to undefined function Home \ Controller \ tgbz_zd_cl ()
Error location
FILE: D: \ WWW \ User \ Home \ Controller \ CommonController. class. php LINE: 62
Public function checkAdminSessiona () {// sets the auto-matching function if (! M ('aconfig')-> where (array ('date' => 0)-> find () {$ tgbz_user = M ('tgbz ') -> where (array ('zt '=> '0')-> select (); $ pipeits = 0; foreach ($ tgbz_user as $ val) {// dump (); die; $ jsbz_list = new \ tgbz_zd_cl ($ val ['id']); // The foreach ($ jsbz_list as $ val1) {// echo $ val ['JB ']. '--
'; // Echo $ val1 ['JB'].'
'; If ($ val ['JB'] = $ val1 ['JB '] & $ val ['user'] <> $ val1 ['user']) {// if the match is processed successfully, if (ppdd_add ($ val ['id'], $ val1 ['id']) {$ pipeits ++; M ('tgbz ') -> where (array ('id' => $ val ['id'])-> save (array ('CF _ DS' => '1 ')); break ;}}// $ this-> error ('/admin. php/Home/Index/zdpp_cl ');}}
Wide-eyed and clear
\ Namespace \ class name: method name ()