Search code examples
cakephpcakephp-bakecake-console

Changing view file extension -via cake bake


Is there a way to change the extension of the view files generated by cake bake view? Presently, the task generates .ctp files -whereas I want .php.

I tried using the alias argument @ cake bake view MyController index "index.php", however CakePHP thinks I am trying to load a plugin named "index": Error: Plugin index could not be found

Obviously, I can change the file names manually or through a batch script. However, it would be ideal for the console to do this.

Edit: Through answering Salines' question as to why I want to do this, I realized this question is more IDE specific. I found what I was looking for in this answer: Display CTP Files as PHP Files in PHPStorm. That said, I would still be interested in knowing if/how to generate alternative file extensions with cake bake view.


Solution

  • How to bake views with custom extensions?

    1. Copy folders Command and Templates from cakephp\lib\Cake\Console to cakephp\app\Console
    2. Go to app\Console\Command\Task open ViewTask file, search for .ctp in code and replace with .php extension, do same for TemplteTask.
    3. Go to app\Console\Templates\default\views, change extension from .ctp to .php for form, index and view files.
    4. Go to app\Console\Templates\skel\View find all .ctp files and change to .php
    5. In your AppController.php set public $ext = '.php';
    6. Bake your views, choose from app\Console

    Note: your CakePHP application will not be made in the standard approach, which can make it difficult for future upgrades. I did not use cakephp views with custom extensions, but I give you instructions on how to do.