Baking custom Controller templates in CakePHP 3 - cakephp

Trying to bake my controllers from a custom template.
As per the cookbook, I've baked a new plugin, and created the following directories:
plugins/MyTemplate/src/Template
plugins/MyTemplate/src/Template/Bake
plugins/MyTemplate/src/Template/Bake/Controller
plugins/MyTemplate/src/Template/Bake/View
In Bake/View I've created the basic CRUD templates, and they're baking fine. In Bake/Controller I've created a controller.twig file. It appears to be ignored. What am I missing?

Related

Use CakePHP applications layout in plugin

I am writing a CakePHP plugin which does not have its own layout but utilises the layout of the application. I tried achieving this by just not creating the /Layout folder in the plugin BUT if i do that the controller crashes with a "Missing Route" error.
All tutorials are showing me how to use a plugin's Layout in my CakePHP application, but i want the opposite.
I am using CakePHP 3.X.
if you don't want to create a view file for the controller method, then just try using line below in that controller method.
$this->autoRender = false;

How to get an interactive console when baking a plugin in CakePHP?

Using CakePHP 2.6.7
When baking a normal part of an application (e.g. using cake bake model) the console is interactive - it goes through the construction process asking for you to choose options at each stage.
But when using cake bake model MyModel --plugin MyPlugin to do the same for a plugin no options are displayed and it generates the model in the plugin folder using default settings.
Is there a way to make the generation of the individual parts of a plugin interactive in the same manner? (this goes for model/controller/view)
When a model in a plugin is baked using cake bake model MyModel --plugin MyPlugin it uses scaffolding. To avoid this you have to use cake bake model --plugin MyPlugin and then the first option presented will allow you to choose from the possible models to be baked.
Replace model with controller/view as appropriate to bake those as well.

import Only CakePHP Html Helpers in Custom MVC project

I have an unusual task at hand, I just need to import a specific portion of CakePHP framework in my custom MVC project, i.e HTML helpers.
Can anyone tell me what code libraries from CakePHP do I need to transfer into my project , to do this.
Please note I need only HTML helpers from the CakePHP framework.
Thanks.
Just go to the CakePHP Github repository Helper directory and download them: https://github.com/cakephp/cakephp/tree/master/lib/Cake/View/Helper

CakePHP and scaffold views

Where can I edit scaffold views?
In Cake Book is information about:
Custom scaffolding views for a specific controller
(PostsController in this example) should be placed like so:
/app/views/posts/scaffold.index.ctp
/app/views/posts/scaffold.show.ctp
/app/views/posts/scaffold.edit.ctp
/app/views/posts/scaffold.new.ctp
Custom scaffolding views for all controllers should be placed like so:
/app/views/scaffolds/index.ctp
/app/views/scaffolds/show.ctp
/app/views/scaffolds/edit.ctp
/app/views/scaffolds/new.ctp
/app/views/scaffolds/add.ctp
But it's not work for my application. So, how to edit scaffold views?

What is a .ctp file used for in CakePHP?

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

Resources