search
HomeBackend DevelopmentPHP TutorialThinkPHP框架的的流程统制-请求视图页面

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);//调整变为开发模式

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
PHP and Python: Different Paradigms ExplainedPHP and Python: Different Paradigms ExplainedApr 18, 2025 am 12:26 AM

PHP is mainly procedural programming, but also supports object-oriented programming (OOP); Python supports a variety of paradigms, including OOP, functional and procedural programming. PHP is suitable for web development, and Python is suitable for a variety of applications such as data analysis and machine learning.

PHP and Python: A Deep Dive into Their HistoryPHP and Python: A Deep Dive into Their HistoryApr 18, 2025 am 12:25 AM

PHP originated in 1994 and was developed by RasmusLerdorf. It was originally used to track website visitors and gradually evolved into a server-side scripting language and was widely used in web development. Python was developed by Guidovan Rossum in the late 1980s and was first released in 1991. It emphasizes code readability and simplicity, and is suitable for scientific computing, data analysis and other fields.

Choosing Between PHP and Python: A GuideChoosing Between PHP and Python: A GuideApr 18, 2025 am 12:24 AM

PHP is suitable for web development and rapid prototyping, and Python is suitable for data science and machine learning. 1.PHP is used for dynamic web development, with simple syntax and suitable for rapid development. 2. Python has concise syntax, is suitable for multiple fields, and has a strong library ecosystem.

PHP and Frameworks: Modernizing the LanguagePHP and Frameworks: Modernizing the LanguageApr 18, 2025 am 12:14 AM

PHP remains important in the modernization process because it supports a large number of websites and applications and adapts to development needs through frameworks. 1.PHP7 improves performance and introduces new features. 2. Modern frameworks such as Laravel, Symfony and CodeIgniter simplify development and improve code quality. 3. Performance optimization and best practices further improve application efficiency.

PHP's Impact: Web Development and BeyondPHP's Impact: Web Development and BeyondApr 18, 2025 am 12:10 AM

PHPhassignificantlyimpactedwebdevelopmentandextendsbeyondit.1)ItpowersmajorplatformslikeWordPressandexcelsindatabaseinteractions.2)PHP'sadaptabilityallowsittoscaleforlargeapplicationsusingframeworkslikeLaravel.3)Beyondweb,PHPisusedincommand-linescrip

How does PHP type hinting work, including scalar types, return types, union types, and nullable types?How does PHP type hinting work, including scalar types, return types, union types, and nullable types?Apr 17, 2025 am 12:25 AM

PHP type prompts to improve code quality and readability. 1) Scalar type tips: Since PHP7.0, basic data types are allowed to be specified in function parameters, such as int, float, etc. 2) Return type prompt: Ensure the consistency of the function return value type. 3) Union type prompt: Since PHP8.0, multiple types are allowed to be specified in function parameters or return values. 4) Nullable type prompt: Allows to include null values ​​and handle functions that may return null values.

How does PHP handle object cloning (clone keyword) and the __clone magic method?How does PHP handle object cloning (clone keyword) and the __clone magic method?Apr 17, 2025 am 12:24 AM

In PHP, use the clone keyword to create a copy of the object and customize the cloning behavior through the \_\_clone magic method. 1. Use the clone keyword to make a shallow copy, cloning the object's properties but not the object's properties. 2. The \_\_clone method can deeply copy nested objects to avoid shallow copying problems. 3. Pay attention to avoid circular references and performance problems in cloning, and optimize cloning operations to improve efficiency.

PHP vs. Python: Use Cases and ApplicationsPHP vs. Python: Use Cases and ApplicationsApr 17, 2025 am 12:23 AM

PHP is suitable for web development and content management systems, and Python is suitable for data science, machine learning and automation scripts. 1.PHP performs well in building fast and scalable websites and applications and is commonly used in CMS such as WordPress. 2. Python has performed outstandingly in the fields of data science and machine learning, with rich libraries such as NumPy and TensorFlow.

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
1 months agoBy尊渡假赌尊渡假赌尊渡假赌
Will R.E.P.O. Have Crossplay?
1 months agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

WebStorm Mac version

WebStorm Mac version

Useful JavaScript development tools

SAP NetWeaver Server Adapter for Eclipse

SAP NetWeaver Server Adapter for Eclipse

Integrate Eclipse with SAP NetWeaver application server.

MinGW - Minimalist GNU for Windows

MinGW - Minimalist GNU for Windows

This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

Atom editor mac version download

Atom editor mac version download

The most popular open source editor