ThinkPHP学习笔记

ThinkPHP学习笔记

2017年1月20日

一. pathinfo模式配置

'配置项'=>'配置值'
'URL_PATHINFO_DEPR'=>'-',
http://localhost/tp/Index-show-name-23423
                     模块  方法  参数

二. 普通模式

http://localhost/tp/index.php?m=Index&a=show&name=123
                              模块     方法    参数

三. 配置url重写模式

1.修改Apache的配置文件 找到文件’rewrite’,去掉前面的#号;
2.添加文件’.htaccess’文件到主目录里;

四. 兼容模式

http://localhost/tp/index.php?s=Index/show/name/123;

2017年1月21日

一. 调用模板

在文件夹里建立和模块名同名的文件夹,然后在文件夹里再建立和方法名同名的html文件

方法一:$this->assign('name','值');
方法二:$this->name = '值';
注意:最后一定要再调用一次模板 $this->display();

二. 修改定界符

 'TMPL_L_DELIM'=>'<{',
 'TMPL_R_DELIM'=>'}>',

三. 本地搭建wamp

输入http://127.0.0.1访问正常,当输入http://localhost/,apache出现You don’t have permission to access/on this server.的提示

找到httpd.conf,用记事本打开httpd.conf,然后将

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Deny from all
</Directory>

这里改成:

<Directory />
    Options FollowSymLinks
    AllowOverride None
    Order deny,allow
    Allow from all
</Directory>

还有一处将下面:

# onlineoffline tag - don't remove
Order Deny,Allow
Deny from all  
Allow from 127.0.0.1
</Directory>

重新启动所有服务

打开localhost或127.0.0.1时发现可以访问了,但访问phpmyadmin时候,出现“You don’t have permission to access /phpmyadmin/ on this server.”的提示。

解决方法,打开文件, C:\wamp\alias\phpmyadmin.conf 
wamp的安装目录下的内容

修改成:

<Directory "c:/wamp/apps/phpmyadmin3.5.1/">
    Options Indexes FollowSymLinks MultiViews
    AllowOverride all
    Order Deny,Allow
    Allow from all
    Allow from 127.0.0.1
</Directory>

修改保存后,重启wamp ,就好了(备注:这部分是借鉴HadoopSpark的博客).

四.数据库信息的调用

1.配置文件链接数据库

//数据库配置
    'DB_TYPE'=>'mysql',//数据库类型
    'DB_HOST'=>'localhost',//服务器
    'DB_NAME'=>'thinkphp',//数据库名
    'DB_USER'=>'root',//表名
    'DB_PWD'=>'',//密码
    'DB_PORT'=>'3306',//端口
    'DB_PREFIX'=>'tp_'//表前缀

2.查询数据库资料

//导出数据库信息
        $m=new Model('User');
        $arr=$m->select();
        var_dump($arr);

3.赋值模板,显示输出

//控制器赋值
    $this->arr=$arr;

//模板显示数据
    <{$arr[1]['username']}>

这样就能调用数据库信息了.

4.使用DSN链接数据库

'DB_DSN'=>'mysql://root:@localhost:3306/thinkphp',

//当有DSN方式和普通数据库链接方式的时候,以DSN方式为主

5.model的实例化简写,及其他的简写方式

$m = M('User');
$arr = $m->select();
var_dump($arr);

//在ThinkPHP中 "增 删 改 查" 的四个简写方式
    //增 -C Create $m->add()
    //删 -D Delete $m->delete()
    //改 -U Update $m->save()
    //查 -R Read   $m->select()

六. 补充

1.模板遍历数据

//控制器中
$m=M('User');//选中实例化数据表
$arr=select();//查询数据内容
$this->assign('arr',$arr);//赋值给前台模板

//模板中
<!-- 使用volist进行模板循环输出 -->
<volist name='arr' id='vo'>
    <{$vo['id']}>----<{$vo['name']}>----<{$vo['sex']}><br>
</volist>

2.开启页面trace功能

//1.在index.php文件中打开调试模式
define('APP_DEBUG',true)

//2.配置文件加载
'SHOW_PAGE_TRACE'=true,
posted @ 2022-12-06 22:23  轻风细雨_林木木  阅读(39)  评论(0编辑  收藏  举报