ThinkPHP入门之又是Hello World
<div style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">PHP入门教程<span style="color: black;">已然</span>结束,学会了基本的交互、输出、数据库操作之后,<span style="color: black;">倘若</span>你想学习<span style="color: black;">更加多</span>原生PHP的知识,<span style="color: black;">能够</span>前往PHP官网(http://www.php.net),W3school(</p>http://www.w3school.com.cn/php)<span style="color: black;">或</span>菜鸟教程(http://www.runoob.com/php)继续学习。从今天<span style="color: black;">起始</span>,我将<span style="color: black;">起始</span>正式跟<span style="color: black;">大众</span>分享ThinkPHP的教程。
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/3e68000190dae4ffd34d~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729831800&x-signature=CrrWzHMTX8H2DI%2ByjF6l%2FJgxtB8%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ThinkPHP</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">获取ThinkPHP</p>
</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">获取ThinkPHP的方式有<span style="color: black;">非常多</span>,<span style="color: black;">不外</span>我<span style="color: black;">举荐</span><span style="color: black;">大众</span>从ThinkPHP官网(http://www.thinkphp.cn)获取最新版本,进入ThinkPHP官网,点击上方导航栏下载,找到ThinkPHP3.2.3完整版并下载。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/400c00015aaf337db9ba~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729831800&x-signature=j87REpHY30YSbqeqtlx3i3DKvL4%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ThinkPHP下载</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">安排</span>ThinkPHP</p>
</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在Web根目录下新建think文件夹,并将文件解压到think文件夹,<span style="color: black;">而后</span><span style="color: black;">拜访</span>localhost/think,<span style="color: black;">就可</span>看到默认ThinkPHP首页内容。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/40090002f62b2561c651~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729831800&x-signature=M3kc4va6P1ErB%2Fr1A0AIi%2Fcg1eg%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ThinkPHP默认首页</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">此时think目录结构如下:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/400b0002dff151769242~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729831800&x-signature=7Qo%2BYYvKfdIVe261AJ7voOAtL9o%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">目录结构</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ThinkPHP简介</p>
</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ThinkPHP是一个快速、兼容<span style="color: black;">况且</span>简单的轻量级国产PHP<span style="color: black;">研发</span>框架,<span style="color: black;">运用</span>面向对象的<span style="color: black;">研发</span>结构和MVC模式(关于MVC模式我将单独发教程)。<span style="color: black;">此刻</span><span style="color: black;">广泛</span><span style="color: black;">运用</span>的是3.2.3和5.0.x版本,前者<span style="color: black;">重点</span>面向普通Web<span style="color: black;">研发</span>,后者<span style="color: black;">重点</span>面向API<span style="color: black;">研发</span>,<span style="color: black;">咱们</span><span style="color: black;">首要</span>学习ThinkPHP3.2.3版本的<span style="color: black;">研发</span>。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">直接输出</p>
</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">编辑think\Home\Controller\IndexController.class.php,将默认代码修改为如下内容:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/4008000301c419d4f814~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729831800&x-signature=pKP5KPtVWs7JeSM%2FZL1Yu3KYk0k%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Hello World代码</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">而后</span><span style="color: black;">咱们</span>刷新网页,<span style="color: black;">就可</span>看到输出的Hello World,是不是超简单?</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/4009000302dae0ebd4d8~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729831800&x-signature=TD9XJ%2BOm5lCwDernndiHc6HdHjU%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Hello World内容</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">$this->show()是ThinkPHP内置的模板输出函数,除此之外,<span style="color: black;">咱们</span>还<span style="color: black;">能够</span><span style="color: black;">运用</span>下面的代码来输出Hello World:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/400b0002ec1e5afa6393~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729831800&x-signature=SeKzEUBgkH0QoyX5eH1v1STXiRg%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">输出函数</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">模板输出</p>
</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">在think\Home\View目录下新建Index目录,并新建index.html文件,代码如下:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/400c0001773baf70c530~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729831800&x-signature=sbtH5L07ypcsCk4hAnIO1%2BbgD90%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">index模板代码</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">而后</span>将IndexController.class.php代码修改为如下内容</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/400800030d1b8f657ee3~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729831800&x-signature=aYP2H%2FHFVUCIaP6bgNDxSYA715E%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Index<span style="color: black;">掌控</span>器代码</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">刷新页面,<span style="color: black;">就可</span>看到输出的两个Hello World:</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/400b0002f0b218400e6f~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729831800&x-signature=07S6ZavmEievs5uVlsZj59gDGpc%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">Hello World页面</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">第1</span>个Hello World是模板内容,第二个Hello World<span style="color: black;">是由于</span><span style="color: black;">掌控</span>器赋值的$hello变量内容。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">掌控</span>器简介</p>
</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">ThinkPHP的<span style="color: black;">掌控</span>器是一个类,操作是<span style="color: black;">掌控</span>器的一个公共<span style="color: black;">办法</span>(关于类和<span style="color: black;">办法</span>的定义属于面向对象的<span style="color: black;">研发</span><span style="color: black;">办法</span>,<span style="color: black;">日前</span>不<span style="color: black;">详细</span>介绍),<span style="color: black;">掌控</span>器<span style="color: black;">一般</span>要继承Controller类,<span style="color: black;">运用</span>驼峰法命名(关于驼峰法命名请<span style="color: black;">自动</span>百度),即“<span style="color: black;">掌控</span>器名+Controller.class.php”。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>上面<span style="color: black;">运用</span>的IndexController.class.php<span style="color: black;">便是</span>一个<span style="color: black;">掌控</span>器,里面的index<span style="color: black;">便是</span>操作<span style="color: black;">办法</span>。<span style="color: black;">因为</span>Home模块为默认模块,Index控制器为默认<span style="color: black;">掌控</span>器,index<span style="color: black;">办法</span>为默认<span style="color: black;">办法</span>,<span style="color: black;">因此</span><span style="color: black;">咱们</span><span style="color: black;">能够</span>直接<span style="color: black;">经过</span>localhost/think来<span style="color: black;">拜访</span>到,其完整路径为</p>localhost/think/index.php/Home/Index/index。
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span><span style="color: black;">咱们</span>在Index<span style="color: black;">掌控</span>器下新建一个test<span style="color: black;">办法</span>,其路径为</p>localhost/think/index.php/Home/Index/test
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><img src="https://p3-sign.toutiaoimg.com/400b0002f96e920f8baf~noop.image?_iz=58558&from=article.pc_detail&lk3s=953192f4&x-expires=1729831800&x-signature=nIrEIbeUnfX5bvmfCqbxKiUSOHA%3D" style="width: 50%; margin-bottom: 20px;"></p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">test<span style="color: black;">办法</span></p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">模版简介</p>
</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">咱们</span>创建的think\Home\View\Index\index.html<span style="color: black;">便是</span>index<span style="color: black;">办法</span>的模板文件,其路径规则为“项目目录\View\<span style="color: black;">掌控</span>器名\<span style="color: black;">办法</span>名,模板后缀名默认为.html。</p>
<h1 style="color: black; text-align: left; margin-bottom: 10px;">
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;">总结</p>
</h1>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">经过</span>简单Hello World程序,<span style="color: black;">咱们</span><span style="color: black;">能够</span>学到ThinkPHP的数据数据方式,<span style="color: black;">掌控</span>器、模板的<span style="color: black;">运用</span><span style="color: black;">办法</span>,<span style="color: black;">咱们</span><span style="color: black;">已然</span><span style="color: black;">把握</span>了ThinkPHP学习的<span style="color: black;">第1</span>步,后面<span style="color: black;">咱们</span>将学习ThinkPHP的CURD操作(数据库操作)。</p>
<p style="font-size: 16px; color: black; line-height: 40px; text-align: left; margin-bottom: 15px;"><span style="color: black;">倘若</span>您觉得<span style="color: black;">博主</span>的教程对您有所<span style="color: black;">帮忙</span>,请点击关注支持<span style="color: black;">博主</span>,您的关注是对<span style="color: black;">博主</span>最大的鼓励。</p>
</div>
楼主果然英明!不得不赞美你一下! 哈哈、笑死我了、太搞笑了吧等。
页:
[1]