PHP开发(33)-ThinkPHP5.0(5)命名空间与TP5-PhpStorm

黄舟
发布: 2023-03-06 10:42:02
原创
2175 人浏览过

在前2篇命名空间的博文基础上,我们来看一下,命名空间、公共空间 与 ThinkPHP5..0之间的关系:

1、controller控制器

首先我们找到index的控制器(controller),

\application\index\controller\Index.php,

修一下,修改后的Index.php:

<?php
    namespace app\index\controller;
    use think\Controller;
    class Index extends Controller
    {
        public function index(){
            return $this->fetch();
        }
    }
登录后复制

2、view视图

然后我们手动创建下面2个文件夹view和index,并创建用于控制index视图的index.html,

\application\index\view\index\index.html,

创建好的index.html:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>iwanghang
</head>
<body>

</body>
</html>
登录后复制

还记得我们的入口文件吗?

\public\index.php,没有做任何修改,我们运行一下,打印结果是iwanghang

<?php
// +----------------------------------------------------------------------
// | ThinkPHP [ WE CAN DO IT JUST THINK ]
// +----------------------------------------------------------------------
// | Copyright (c) 2006-2016 http://www.php.cn/ All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.php.cn/ )
// +----------------------------------------------------------------------
// | Author: liu21st <liu21st@gmail.com>
// +----------------------------------------------------------------------

// [ 应用入口文件 ]

// 定义应用目录
define(&#39;APP_PATH&#39;, __DIR__ . &#39;/../application/&#39;);
// 加载框架引导文件
require __DIR__ . &#39;/../thinkphp/start.php&#39;;
登录后复制

 以上就是PHP开发(33)-ThinkPHP5.0(5)命名空间与TP5-PhpStorm的内容,更多相关内容请关注PHP中文网(www.php.cn)!


来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!