What is a .ctp file used for in CakePHP?

匿名 (未验证) 提交于 2019-12-03 02:50:02

问题:

I'm starting to use CakePHP, and I'm in the process of reading the manual. About halfway down the page, there's this comment:

// Render the element in /views/elements/ajaxreturn.ctp 

So a very simple question: what's the .ctp extension refer to? What's the general use case?

Thanks.

回答1:

CakePHP 1.2 introduced .ctp as its file extension for views.

CakePHP view files are written in plain PHP and have a default extension of .ctp (CakePHP Template). These files contain all the presentational logic needed to get the data it received from the controller in a format that is ready for the audience you’re serving to.

http://book.cakephp.org/2.0/en/views.html#view-templates



回答2:

Template file used by CakePHP, a development framework for PHP Web applications; contains the PHP "view" code within the Model-View-Controller (MVC) software architecture design pattern; stores a template for how information is displayed in the Web application.

See more in http://www.fileinfo.com/extension/ctp



回答3:

You can change the .ctp file extention by using property in Controller or AppController:

public $ext = '.php'; 

.ctp is the view file extention of CakePHP template file. It stands for "CakePHP Template".



回答4:

CakePHP provides an extendable architecture for designing, developing and distributing software using a rapid development framework. The .CTP file extension supports CakePHP's view scripts and provides the set of helpers appropriate for CakePHP version 1.2.

http://book.cakephp.org/2.0/en/views.html#view-templates



回答5:

Cakephp follow 3-tier architecture, Model ,Controller and View are 3-tier of this architecture.All MVC Framework follows this architecture Including Cakephp, .ctp extension used by Cakephp views.

S.jpg


回答6:

ctp stands for CakePHP Template

It is a template file used by CakePHP. Basically it is a application View layer, it contains the PHP,Html "view" code to display the end user.



回答7:

Cakephp is based on MVC framework. 'M' stands for model, 'C' for Controller and 'V' for Views. Model is used for interacting with database tables, Controller used for controlling request and response of client and also for logic implementation and process and views are for presentation. Other two have file extension .php, but views has .ctp extension. Reason is that Cakephp architecture is using template caching internally, such as tpl in Smarty.



回答8:

CTP files may contain layouts, elements, or helpers. Layouts define presentation code. Elements contain smaller, reusable segments of view code. Helpers contain classes that encapsulate logic used between many views, elements, or layouts.

CTP files are stored in the CakePHP /app/views directory.



回答9:

the ctp file type in cakePHP is used for views it can be used to represent :

1. The standard views, wich are related to a model and a controller; 2. Elements, wich can be inserted in other views (Pages, or standard view); 3. Pages : Static pages . 

Inside a view you can use HTML and PHP, and in the most of cases you have an object available, wich represent the model (Example $Product).



回答10:

CakePHP's View Class has a class varibale called $viewExtension or perhaps $viewExt and its default value is set to 'ctp' which stands for cake php template, you can over write this value in any of your controller or in derived view classes or in any controller action within the scope of code.



回答11:

.ctp files are CakePHP Template Pages, that is view templates. It is used for the view in the MVC that shows output in the browser and act as a view for a controller action. JSON, XML, HTML, JS, CSS, PHP code can be written in it. More than as HTML/PHP pages, it shows data sent from controller. Also .ctp files CakePHP can act as a layout that wraps the view around it.



回答12:

Its a view file from where controller render the presentation login.You can change the extension ".ctp" to ".php" for views to set the $ext property for specific controller $this->ext = '.php'



标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!