ThinkPHP框架的的流程统制-请求视图页面
ThinkPHP框架的的流程控制-请求视图页面
ThinkPHP框架今天看了一下,感觉确实比zend方便了很多,之所以不看zend,是因为我是在是受不了了,难度太大,以至于我一个小时的视屏看了六遍也没有搞明白,这样的话,后面的东西我就无法进行,因为之间的联系性很大,所以,索性循循渐进把,把THINKPHP学习一下,然后再过度到zend,果然,经过学习,发现ThinkPHP的框架要比zend
简单了很多,一方面是他的配置相对较为简单,知识仅仅的配置好虚拟主机就可以了,这个在zend是很难想象的,另外,对于方法的调用也相对的较为方便,因为它不像zend封装的那么厉害让你找不到所以然,然后就是目录结构很清晰,直接引入库文件就可以直接调用方法,如只用display()方法就可以取调用视图页面,还有一方面就是有很好的可扩展性,不像zend那样几乎一动不能动,但是tp也是有缺点的,他的优点也就是他的缺点,虽然方便,但是在功能的强大上确实是比不上zend,这一点必须承认,因此,可以把tp当做zend的一个过渡教程。
那么,think的运行流程又是什么样的呢?
首先,打我们建立好虚拟主机并把所有的目录都准备完成之后,如果请求站点名称,首先呈现给我们的是tp的欢迎界面,紧接着,你会发现所有的东西如目录全部都给你配置完成,这就非常的方面了,包括模型试图控制器等,然后我会要测试的就是条用视图的测试了。
调用视图页面很简单,这样,我们在控制器里面建立你要在view里面建立的文件名的控制器文件(很绕口,实例一下就明白了),但千万不能忘了继承控制器类,这样才能够继续进行下去,用display()的方法去请求视图对应页面,这样,很简单的就完成了视图的显示,整个分层的思想也显现出来了。
但是,我在具体测试的时候,还是遇到了一些问题:
首先是路径问题,学习zend就在路径问题上给卡住了,因为我就是不明白我的文件为什么不能用重写机制,但是在tp里面,变得清晰了,因为tp把路径分为了四种分别为:get路径模式,完全路径模式,重写路径模式,和兼容路径模式,这里我只是选用了get路径模式进行测试,但是要修改配置文件的话就得去config.php去修改,不要去系统里面去修改,就像下面的那样在config里面:
return array(
//'配置项'=>'配置值'
//设置为兼容的路径模式
'URL_MODLE' => 3,
//设置显示调试信息
'SHOW_PAGE_TRACE' => true,
//url不敏感设置
'URL_CASE_INSENSITIVE'=> true,
);
这是路径方面遇到的问题,另外就是引入外部文件;
关于这个,没有说明对与错,只是方便和规范的问题,我是这么建议的,外部文件如css。js,image等都已绝对路径的方式显示,一方面快而准确,另一方面便于修改。
可以在index入口文件设置好常量地址:
define("SITE_URL","http://mytest.com/");
define("CSS_URL",SITE_URL."Public/css/");
define("JS_URL",SITE_URL."Public/js/");
define("IMAGE_URL",SITE_URL."Public/js/");
在视图引入的时候可以这样引入:
最后还有一个建议就是开启开发模式,有利于自己清楚的了解信息,便于调试:
define("APP_DEBUG",true);//调整变为开发模式

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



The reason for the error is NameResolutionError(self.host,self,e)frome, which is an exception type in the urllib3 library. The reason for this error is that DNS resolution failed, that is, the host name or IP address attempted to be resolved cannot be found. This may be caused by the entered URL address being incorrect or the DNS server being temporarily unavailable. How to solve this error There may be several ways to solve this error: Check whether the entered URL address is correct and make sure it is accessible Make sure the DNS server is available, you can try using the "ping" command on the command line to test whether the DNS server is available Try accessing the website using the IP address instead of the hostname if behind a proxy

To run the ThinkPHP project, you need to: install Composer; use Composer to create the project; enter the project directory and execute php bin/console serve; visit http://localhost:8000 to view the welcome page.

ThinkPHP has multiple versions designed for different PHP versions. Major versions include 3.2, 5.0, 5.1, and 6.0, while minor versions are used to fix bugs and provide new features. The latest stable version is ThinkPHP 6.0.16. When choosing a version, consider the PHP version, feature requirements, and community support. It is recommended to use the latest stable version for best performance and support.

Steps to run ThinkPHP Framework locally: Download and unzip ThinkPHP Framework to a local directory. Create a virtual host (optional) pointing to the ThinkPHP root directory. Configure database connection parameters. Start the web server. Initialize the ThinkPHP application. Access the ThinkPHP application URL and run it.

Differences: 1. Different definitions, url is a uniform resource locator, and html is a hypertext markup language; 2. There can be many urls in an html, but only one html page can exist in a url; 3. html refers to is a web page, and url refers to the website address.

Performance comparison of Laravel and ThinkPHP frameworks: ThinkPHP generally performs better than Laravel, focusing on optimization and caching. Laravel performs well, but for complex applications, ThinkPHP may be a better fit.

"Development Suggestions: How to Use the ThinkPHP Framework to Implement Asynchronous Tasks" With the rapid development of Internet technology, Web applications have increasingly higher requirements for handling a large number of concurrent requests and complex business logic. In order to improve system performance and user experience, developers often consider using asynchronous tasks to perform some time-consuming operations, such as sending emails, processing file uploads, generating reports, etc. In the field of PHP, the ThinkPHP framework, as a popular development framework, provides some convenient ways to implement asynchronous tasks.

The importance and role of the define function in PHP 1. Basic introduction to the define function In PHP, the define function is a key function used to define constants. Constants will not change their values during the running of the program. Constants defined using the define function can be accessed throughout the script and are global. 2. The syntax of define function The basic syntax of define function is as follows: define("constant name","constant value&qu
