Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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

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".

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.

CTP files are templates for the CakePHP framework for application development, managed by the Cake Software Foundation. CTP files contain information for the program's user interface and dictates how an application appears to the user.... More »

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

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.

enter image description hereS.jpg

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.

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.

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.

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).

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.

.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.

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'

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top