CakePHP 3: How to include simple page .ctp in default.ctp - cakephp

Is it possible? if yes, then how to create a simple page that uses the default.ctp page.
So I want something like the "include" features because my single pages have the same header and footer as my default.ctp and I don't want to write the import scripts (css, js) twice because the paths are differents from src/Template/Layout/default.ctp and src/Template/Pages/*.ctp
Thank you. I'm a newbie on CakePHP and I started with version 3.

You can use in your Controller's View Function:
$this->viewBuilder()->layout('custom');
This will use src/Templates/Layout/custom.ctp file instead of default.ctp
You can (but you shouldnt), only add few html tags on this file and populate everything else in your src/Templates/Pages/*.ctp files

Related

how to make seperate Admin folder in cakephp 3

I am using cakephp 3 and first time using it.I found that I can make controller only in \src\Controller. Here I have put all front end related files. Now I want to make seperate Admin section front end. Please guide how I can do it.
You may want to look at prefixed routing:
http://book.cakephp.org/3.0/en/development/routing.html#prefix-routing
Create a folder inside src/Controller eg src/Controlelr/Admin/. Then you can create a controller src/Controller/Admin/UsersController.php and the view file src/Template/Admin/Users/edit.ctp.

Whta if I don't use app/webroot/index.php

I know that the index.php requires many files like core,dispatch,bootstrap and so on.This time in my project,I directly use a html inseide which has a ,and
the href is "topath/app/houses/init"(created by myself).The question is that,how about the index.php and the files it requires?Should they be required actually?
Thank you very much.
yes index.php required those files to load cake api, and dispatcher api's.
if you need a plain html then you can use following structure
topath/app/index.html which contain anchor tag to redirect on your
specified app
topath/app/houses is an cakephp app that contains all your houses app
content
if you have multiple cakephp app then you can seperate cake api
keep cake api out side from app
mainapp/cake/ include all cakephp api lib
mainapp/houses/ include all houses app code
update mainapp/houses/app/webroot/index.php to load cake api from
mainapp/cake/
and so on......
hope it will help you

Change Angularjs existing backend to Play 2

I have a fully developed Angularjs frontend app (with the routes and everything set up) and would like to change the current backend to a Play 2 Java. What is the best approach to display the existing html files from Angular in Play? I have found a few examples of how to connect the routes, but I would rater not create an index.scala.html file as I would like to have the two frameworks separated as much as possible and having Play only working as backend.
If you don't want to dynamically generate views from Play using Twirl and you just want to serve your HTML static files publishing them as assets is the way to go. By default assets are designed to provide resource like CSS or JS files but nothing prevents you from serving ordinary HTML views as well.
Simply put your index.html in the public directory and modify the conf/routes files so it can handle all requests:
GET /*file controllers.Assets.at(path="/public", file)
This way your index.html will be accessible at www.yourdomain.com/index.html. Remember to put this line as the last mapping in the file as it matches all possible URLs. Other services should be declared above it.

use one large external file for many javascript templates with backbone.js?

I have two different HTML pages that serve up backbone apps. Up until now, I have put all the js templates inside of each respective HTML file.
Now, I'm refactoring a bit and would like to share some backbone views between files. When loading a view that can't find a js template, the whole app will error out. I know the proper way to merge these two would be to have external js templates, using EJS for example, and have 1 template per file, however, I'd like to just have one huge HTML file with embedded <script type='text/template'> and share the template HTML file between my 2 pages. Is this possible? I tried getting the external js templates with AJAX and writing them to the head, but backbone views still can't find them.
Does anyone else choose to have a file with many javascript templates in it? I also find that I have an unmanageable number of files open when I use ejs. Any help would be most appreciated.
I use an extra javascript/coffeescript file and use underscore's templating to take care of everything. This way you can include the templates and put them into as few (or many) files as you would like.
I'm using a single file for all the templates on my current project and it is working out pretty well.
It's a Asp.Net site, so I made the template file into a user control so I can easily include it in any page that uses Backbone.
If you're fetching all templates through AJAX, maybe you don't have to write them to the head.
You can send templates to the client as JSON Object, for example:
{"about":"<p>About</p>...","gallery":"<p>Gallery</p>...","contact":"<p>Contact</p>..."}
After fetching temples you can store them as templates variable inside some object(or locale storage), and after that you can do the following:
var tempStr = templates['about'],
template = new EJS({element:{value: tempStr, id: 'about'}}),
content = template.render();

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