TP框架控制器里面怎么调用另一个控制器的代码

WBOY
Release: 2016-06-23 13:18:07
Original
1756 people have browsed it

我网站TP框架,一个前台D:\WWW\User\Home\Controller\CommonController.class文件,一个后台D:\WWW\snadmin\Home\ControllerCommonController.class文件,    我想在前台的文件里面调用后台里面的代码,不知道可不可以?

前台CommonController.class文件代码

<?phpnamespace Home\Controller;use Think\Controller;class CommonController extends Controller{    public function _initialize()    {     $this->checkAdminSessiona();  //这样调用后台CommonController.class文件的public function checkAdminSessiona() ,这样调用错误,不知道有没有好的办法?         }	}	}
Copy after login




后台CommonController.class文件代码
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;
}
}
}
}
}
}


回复讨论(解决方案)

可以啊

use Think\Controller;
Copy after login
Copy after login
Copy after login

use方法

可以啊

use Think\Controller;
Copy after login
Copy after login
Copy after login

use方法

能在具体点吗

可以啊

use Think\Controller;
Copy after login
Copy after login
Copy after login

use方法



我已经用了 我是要调用另个一CommonController.class控制器文件代码

非静态的方法:实例化后调用
静态的方法:实直接静态调用

非静态的方法:实例化后调用
静态的方法:实直接静态调用




静态的方法:实直接静态调用 怎么写啊代码

没在你示例的代码中看到静态方法的定义

如果确实有定义的话,则
\命名空间\类名::方法名()

没在你示例的代码中看到静态方法的定义

如果确实有定义的话,则
\命名空间\类名::方法名()



后台D:\WWW\snadmin\Home\ControllerCommonController.class文件

前台D:\WWW\user\Home\ControllerCommonController.class文件

Call to undefined function Home\Controller\tgbz_zd_cl()
错误位置
FILE: D:\WWW\User\Home\Controller\CommonController.class.php  LINE: 62


	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) {            //dump();die;            $jsbz_list =new \ tgbz_zd_cl($val['id']);             //提示错误的就是这句            foreach ($jsbz_list as $val1) {                //echo $val['jb'].'--<br>';                //echo $val1['jb'].'<br>';                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;                    }                }            }        }//$this->error('/admin.php/Home/Index/zdpp_cl');         } 	}
Copy after login

睁大眼睛看清楚了
\命名空间\类名::方法名()

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template