thinkphp 跨模块调用

来源:互联网 发布:网页图片制作软件 编辑:程序博客网 时间:2024/05/23 01:30
项目简介:
测试项目名为Tp3.0
访问网址:localhost/Tp3.0
安装环境:windows+apache+mysql+php
安装目录:D:\AppServ\www\Tp3.0
模块分组:测试时将模块分为两组Home,Admin,根据需求还可以添加更多分组,比如:Home,Admin,User,Article。。。
一、跨模块调用实例:
简介:在Index模块中调用Goods模块。
1、测试两个模块Index和Goods两个模块,这两个模块是在同一Home组下面,具体路径为:
D:\AppServ\www\Tp3.0\Lib\Action\Home\IndexAction.class.php
D:\AppServ\www\Tp3.0\Lib\Action\Home\GoodsAction.class.php
2、两个模块的详细代码如下:
IndexAction.class.php详细代码如下:
<?php
// 本类由系统自动生成,仅供测试用途
class IndexAction extends Action {
    public function index(){
        $Goods = new GoodsAction(); //调用同在Home组下面的Goods模块
        $Goods = A('Home/Goods'); //调用Goods模块的另外一种方法,效果同上面的new GoodsAction()一样,
        $goods_list = $Goods->index();
        var_dump($goods_list);
        $User = new Model('category');
        $users = $User->where('top_id = 1')->select();
        $this->display();
      
    }
}
?>
GoodsAction.class.php详细代码如下:
<?php
class GoodsAction extends Action
{
    public function __construct()
    {
   
   
    }
    function index()
    {
        $Goods = M('goods');
        $goods_list = $Goods->select();
        var_dump($goods_list);
    }

}
?>
0 0
原创粉丝点击