Home  >  Article  >  php教程  >  第一次使用TP5.0新建项目

第一次使用TP5.0新建项目

不言
不言Original
2018-05-29 10:05:402821browse

第一次使用TP5.0新建项目
仅供参考。
安装问题中所属:新建一个项目,下属:shop,cms,weixin,mobile四个模块(这里暂时称之为模块吧)
一、将你的网站住目录设置为 ./public也就是说,你的网站主目录是public目录,github中的其他两个目录随意你放到任何位置,但是前提是,根据文件引用规则,确实能够相互引用。
public中默认有:├─public                WEB目录(对外访问目录)<br>│  ├─index.php          入口文件<br>│  ├─.htaccess          用于apache的重写<br>│  └─router.php         快速测试文件(用于PHP内置webserver)这也就意味着,在tp5.0的版本中,你的网站主目录里将不会出现框架目录和项目目录(这样说可能略显复杂了,也就是说:把所有不用直接访问的文件都移到网站目录外面了,这样为了安全。)。
虚拟主机或者不支持自定义主目录的云主机中,请将本目录里所有文件复制到外面的主目录中,并修改相应的引用。
也就是tp3.0的方式,否则:你只能使用:http://think.com/public/index.php来访问了。

二、项目文件的自动生成
从github上clone的时候,默认项目目录中是有文件的,安装问题中所述,是不想要index这个模块的,所以可以把application目录里的文件全部删除(你最好不要删除这个目录)。
然后,复制github库中的‘build.php’到‘application’
并修改为:

<?php
return [
    // 生成运行时目录
    &#39;__dir__&#39;  => [&#39;runtime/cache&#39;, &#39;runtime/log&#39;, &#39;runtime/temp&#39;],
    &#39;__file__&#39; => [&#39;tags.php&#39;],
    //其实,如果上面的改成:&#39;__file__&#39; => [&#39;tags.php&#39;,&#39;config.php&#39;], 那么config.php 也会自动创建
    // 定义shop模块的自动生成
    &#39;shop&#39;    => [
        &#39;__file__&#39;   => [&#39;tags.php&#39;],
        &#39;__dir__&#39;    => [&#39;behavior&#39;, &#39;controller&#39;, &#39;model&#39;, &#39;view&#39;],
        &#39;controller&#39; => [&#39;Index&#39;, &#39;Test&#39;, &#39;UserType&#39;],
        &#39;model&#39;      => [],
        &#39;view&#39;       => [&#39;index/index&#39;],
    ],
    // 定义cms模块的自动生成
    &#39;cms&#39;    => [
        &#39;__file__&#39;   => [&#39;tags.php&#39;],
        &#39;__dir__&#39;    => [&#39;behavior&#39;, &#39;controller&#39;, &#39;model&#39;, &#39;view&#39;],
        &#39;controller&#39; => [&#39;Index&#39;, &#39;Test&#39;, &#39;UserType&#39;],
        &#39;model&#39;      => [],
        &#39;view&#39;       => [&#39;index/index&#39;],
    ],
    // 定义mobile模块的自动生成
    &#39;mobile&#39;    => [
        &#39;__file__&#39;   => [&#39;tags.php&#39;],
        &#39;__dir__&#39;    => [&#39;behavior&#39;, &#39;controller&#39;, &#39;model&#39;, &#39;view&#39;],
        &#39;controller&#39; => [&#39;Index&#39;, &#39;Test&#39;, &#39;UserType&#39;],
        &#39;model&#39;      => [],
        &#39;view&#39;       => [&#39;index/index&#39;],
    ],
    // 定义weixin模块的自动生成
    &#39;weixin&#39;    => [
        &#39;__file__&#39;   => [&#39;tags.php&#39;],
        &#39;__dir__&#39;    => [&#39;behavior&#39;, &#39;controller&#39;, &#39;model&#39;, &#39;view&#39;],
        &#39;controller&#39; => [&#39;Index&#39;, &#39;Test&#39;, &#39;UserType&#39;],
        &#39;model&#39;      => [],
        &#39;view&#39;       => [&#39;index/index&#39;],
    ],
    // 。。。 其他更多的模块定义
];

当然,你还要在'index.php'中添加一行代码://你最好在完成自动生成后,把他删除了。<br>define('APP_AUTO_BUILD',true);接着,访问你的域名(或者本地地址),按照上面问题中所属的模块,你会得到一个错误页面
原因很简单,因为默认模块是index,而这个问题所要求的项目中没有index模块。
那么我们要修改配置文件,不过打开项目目录(application),然后进入模块目录,你会发现,哦,你找不到配置文件,是的,根据默认的生成情况来看,配置文件是没有进行生成的(最起码上面的自动生成代码中是没有的)。
那么我们可以自己新建一个,根据tp5.0模板中的介绍,我们可以在项目目录(application)中直接新建一个’config.php‘文件,并写入:

<?
return [
        // 默认模块名
        &#39;default_module&#39;        => &#39;shop&#39;,
        // 禁止访问模块
        &#39;deny_module_list&#39;      => [COMMON_MODULE, &#39;runtime&#39;],
        // 默认控制器名
        &#39;default_controller&#39;    => &#39;Index&#39;,
        // 默认操作名
        &#39;default_action&#39;        => &#39;index&#39;,
        // 默认的空控制器名
        &#39;empty_controller&#39;      => &#39;Error&#39;,
        // 操作方法后缀
        &#39;action_suffix&#39;         => &#39;&#39;,
        // 操作绑定到类
        &#39;action_bind_class&#39;     => false,
    ];

哦,好吧,从这里你会看出,这里是直接复制的’think/thinkphp/convention.php‘中的代码,是的,我想告诉你的就是,如果你遇到问题,直接看tp的源代码,将会获得意想不到的帮助。
哦,是的,ThinkPHP 5 简明开发手册 也是个好地方

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:extend跨模块继承base.htmlNext article:PHP安装OCI8扩展