(3)WePHP控制器与模型

MVC的先进理念就是程序流程 数据库操作 模板制作三个流程分离

大M函数会把模型引入到当前控制器的方法中,注意这个"excel"对应M文件夹的excel.php 同时也是整个excel.php操作的数据库表名,这样每个表它自己对应的操作都在同名PHP中

<?php
class C_index extends Action
{
    public function __initialize()
    {
        echo"自动执行";
    }
    public function index()
    {
        echo "index";
    }
    public function test()
    {
        $a="我是模板";
        $this->assign("pass",$a);
        $this->display();    
        $mo=M("excel");
        $mo->index();
    }
}
?>
<?php
class M_excel extends Model
{
    public function index()
    {
        echo "我是mode2l";
        $row=$this->table("test")->where("1")->select("queryOnce");
        dump($row);
        //$this->select();
        //dump($sqlquery);
        dump("zhenian");
    }
}
?>

 1.M模型输出当前执行SQL $this->querySqlStr

2.C控制器跳转$this->redirect(index/index);

posted @ 2016-02-29 10:32  saws  阅读(293)  评论(0编辑  收藏  举报