How to call the code of another controller in the TP framework controller

Source: Internet
Author: User
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 ()

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.