thinkphp笔记

1.load('@.function')  临时性加载

指的是Common文件下的 function

如 function select(){} , locad中的function实际指的就是 common目录下的select.php文件

用法:

class IndexAction extends Action {
    public function index(){
        load('@.select');
        print_r(say());

    }
}

common 目录下的select.php文件

<?php
function say(){
    echo '0000';    
}

?>

错误写法:

<?php
function say(){
    echo '0000';    
}
function s(){
    echo 'Hello World';    
}

?>

注意select.php文件里面只能有一个  function,多个会出现错误

2.common文件是一个共享类文件

 common下的common.php 会被系统自动加载。另取的名字,如select.php 不会被自动加载

common下的select.php

3.load_ext_file  加载外部文件

4.重新定义__PUBLIC__ 指向路径 ,Index/Conf/config.php 或者是Conf/config.php

<?php
$config = array(
    'LOAD_EXT_FILE'=>'fun',
    'TMPL_PARSE_STRING' => array(
        '__PUBLIC__' => __ROOT__.'/'.APP_NAME.'/Tpl/Public',
    ),
    
);
return array_merge(include('./Conf/config.php'),$config);
?>

 如: __UPLOAD__  映射地址到..

5.URL_HTML_SUFFIX,连接配置

<?php
   'URL_HTML_SUFFIX'=>'htm', 
  'URL_HTML_SUFFIX'=>'.ios',  // 带.  带与不带效果一样
?>

php输出   echo U('Index/index')  结果  index.php/Index/index.htm 或者是  index.php/Index/index.ios

6.输出默认的几项参数

I('id') 相当与  $_get['id']  ,I('get.')输出整个get数组 ,I('post.') 输出整个post数组   版本:3.1.3有效

C() 系统默认配置

U('Index/show',array('id'=>1,'username'=>wang)); html页面输出连接{:U()}  传递方式一样

7.URL_MODEL  连接模型 在config.php

<?php
$config = array(
    'LOAD_EXT_FILE'=>'fun',
    'TMPL_PARSE_STRING' => array(
        '__PUBLIC__' => __ROOT__.'/'.APP_NAME.'/Tpl/Public',
    ),
     'TMPL_TEMPLATE_SUFFIX' =>'.htm',
     'URL_MODEL' => 2,   //0是默认参数
    
);
return array_merge(include('./Conf/config.php'),$config);
?>

8.IS_POST 与 $this->isPost()  判断知否是从表单提交页面过来的,点击submit体提交过来的就是true,直接用地址访问的是 false

实例:

Public function add_ok(){
  if(!IS_POST) _404('页面不存在');  
  echo '提交成功'; }
//如果不是通过表单传递过来的值,就给一个404错误页面;如果是,则显示 提交成功

9.thinkphp 404方法

if(!IS_POST) _404('页面不存在',U('Index'));   如果不是post提交过来,直接跳转到index

if(!IS_POST) halt('页面不存在');  //输错页面,错误信息更详细(错误页面可以定制)
 

10. $this->assign('a','111');  与$this->a=111 与$this->assign('a','0000')->display()  效果一样

原文地址:https://www.cnblogs.com/wesky/p/4946893.html