分组、页面跳转与ajax

来源:互联网 发布:mac团灭 编辑:程序博客网 时间:2024/05/22 07:02
一、多应用配置技巧
        在 thinkphp 下面创建  config.php  生成公共的配置项
        <?php
            return array(
                'DB_PREFIX'=>'tp_',
                'DB_DSN'=>'mysql://root:@localhost:3306/thinphp',
            );
        ?>

        当主入口文件的前提下Index模块下的config.php配置
        <?php
            $arr= include './config.php';
            $arr2=array(
                
            );
            return array_merge($arr,$arr2);
        ?>
二、使用分组
        添加配置:
            'APP_GROUP_LIST' => 'Home,Admin', //项目分组设定
            'DEFAULT_GROUP'  => 'Home', //默认分组
        只有一个配置入口文件 index.php
        <?php
//1.确定应用名称
define('APP_NAME','APP');
//2.确定应用路径
define('APP_PATH','./APP/');
//3.开启调试模式
define('APP_DEBUG',true);
//4.应用核心文件
require './ThinkPHP/ThinkPHP.php';

        启动分组之后访问 /thinkphp/index.php/Home/Index/index
    
        其中在 /thinkphp/APP/Lib 下面创建 Home, Admin 文件夹,将 IndexAction.class.php 放入 
        
项目目录分组(以Home和Admin分组为例)不分组公共目录
(Common)

Home分组:Common/Home/function.php


Admin分组:Common/Admin/function.php


公共文件:Common/common.php

Common/common.php配置目录
(Conf)

Home分组:Conf/Home/config.php


Admin分组:Conf/Admin/config.php


公共配置:Conf/config.php

Conf/config.phpAction目录

Home分组:Lib/Action/Home/


Admin分组:Lib/Action/Admin/


公共Action:Lib/Action/

Lib/Action/Model 目录Lib/Model/Lib/Model/语言包目录(Lang 以zh-cn为例)

Home分组:Lang/zh-cn/Home/lang.php


Admin分组:Lang/zh-cn/Admin/lang.php


公共语言包:Lang/zh-cn/common.php

Lang/zh-cn/common.php模板目录(Tpl以theme主题为例)

Home分组:Tpl/Home/theme/


Admin分组:Tpl/Admin/theme/

Tpl/theme/运行时目录(Runtime)

Home分组:Runtime/Home/


Admin分组:Runtime/Admin/

Runtime/
三、页面跳转
    不同的模块下的模板文件跳转:
$this->success('查询成功',U('User/test'));
    相同的模块下的模板文件跳转:
        $this->success('查询成功','index');

$this->redirect('User/test','',5,'页面正在跳');
        跳转的页面放在 thinkphp/ThinkPHP/Tpl/dispatch_jump.tpl 


        修改页面跳转对应的模板文件:
        //默认错误跳转对应的模板文件
    'TMPL_ACTION_ERROR' => 'Public:error';
    //默认成功跳转对应的模板文件
    'TMPL_ACTION_SUCCESS' => 'Public:success';
四、Ajax技巧
    格式:
        $this->ajaxReturn(返回数据,提示信息,操作状态);

  使用 jQuery 的ajax 方式:
        <script src="__PUBLIC__/Js/jquery.js"></script>   
                  <script>
                        $(function(){
                            $('button').bind('click',function(){
                                    $.get('__URL__/getAjax',function(jdata){
                                             alert(JSON.stringify(jdata));  //输出 data:...info:...status:...
                                              if(jdata.status==1){
                                                        $('div#did').html(jdata.data);
                                              }
                                     });
                           });
                        });
                   </script>

   在 IndexAction.class.php 中创建
            public function getAjax(){
                $this->ajaxReturn('这是我要的数据','信息',1);
            }
0 0
原创粉丝点击