thinkphp5入门

开始第一个项目时的基本须知

  1. 把入口文件 index.php 从 public 里挪到根目录然后 并修改 index.php 里的目录位置

  2. 把 public 里的.htaccess 移动到根目录 可以在 url 里少写一个 index.php

  3. 打开 config.php 页面把第一个 defale 改成 true 开始调试模式
    进入 database.php 文件,把数据库信息改为自己的

  4. 在 /application /index 下创建 view 和 model

    并在 view 下创建 index 目录 在该路下放 index.html 网页

  5. 如果用框架,需要把框架放在 publicstatic 下 引用时

    <link rel="stylesheet" href="public/static/bootstrap.min.css">
    
  6. 在使用 tp5 时,创建新的控制器时,控制器的首字母要大写,方法也要和

文档笔记

use 可以导入一个命名空间的类库 导入之后可以直接调用类库
用封装好的 assign 和 fetch 时要调用 Controller
模板 / 控制器 / 操作
url 驼峰法 开启区分大小写 ,修改 url_convert => 为 false(就是取消 url 强制转换为小写)
如果你的服务器环境不支持 pathinfo 方式的 URL 访问,可以使用兼容方式,
例如:http://tp5.com/index.php?s=/index/Index/index
方法里有参数时,通过 url 这样传参, 在网址后面要加 ?, 参数不用加$符,传多个参数时中间用&链接
或者用 **/ **这种方法简单

http://localhost/php/__tp/index/index/new_list?name='1'&new='2'
http://localhost/php/__tp/index/index/new_list/name/111/new/222

可以对 url 进行简化 修改 'url_param_type' => 1,此时参数必须按照顺序进行书写,按顺序绑定参数的话,操作方法的参数只能使用 URL pathinfo 变量,而不能使用 get 或者 post 变量。

http://localhost/php/__tp/index/index/new_list/111/222

如果觉得访问 操作的时候 url 太长 可以修改 route.php 里添加路由规则 改了之后 就 不用写 模板 控制器了 直接写方法就可以访问到

return [
	添加路由规则 路由到 index控制器的hello操作方法
'hello/:name' => 'index/index/hello',
];
//该路由规则表示所有 hello 开头的并且带参数的访问都会路由到 index 控制器的 hello 操作方法。

闭包就是只有一个方法的类

连表操作模型

$sql=Db::field('s.name,a.*')//截取表s的name列 和表a的全部
    ->table(['表a'=>'a','表s'=>'s'])
    ->where('a.name=s.id')//查询条件语句
    ->select();

Tp5 关于前端页面框架存放位置及引用的方法,还有路由的相关问题总结

当需要用 bootstrap 等框架时,应放到项目根目录:/public/static/ 下

在页面中引用的三种方法:

  1. <link rel="stylesheet" href="/public/static/css/bootstrap.min.css">

  2. {css href="__CSS__/css/bootstrap.min.css"}

  3. //在application/config.php	下第141行处 在中括号[]里 添加框架位置 public前面不要加/
    // 视图输出字符串内容替换
    'view_replace_str'       => [
        "__CSS__" => "public/static/css",
    ],
    

使用了这种方法在页面里引用方式 可以省去写前面的 /public/static/css

<link rel="stylesheet" href="__CSS__bootstrap.min.css">

用 Tp5 使用其他框架后,url 按照 如下方式 不能正确访问到框架

  1. 用 Tp5 使用其他框架后,url 按照 如下方式 不能正确访问到框架

http://localhost/php/__tp/index/index/index

解决办法

  1. http://localhost/php/__tp/ //不详细写到视口

  2. http://localhost/php/__tp/?s=index/index/index //这种是使用兼容格式

以上都是临时的

TP5 项目放在 htdocs 根目录下,项目名称大写,

有什么不同见解可以在评论区共同讨论
原文地址:https://www.cnblogs.com/lambertlt/p/12663436.html