0

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.

Community
  • 1
  • 1
jtrumbull
  • 818
  • 9
  • 19
  • 1
    Can we know why you want to change the file extension? You can write your own console script and view templete. – Salines Feb 23 '15 at 22:00
  • `.ctp` is not recognized by most (if not all) IDEs and Text editors. While editing `.ctp` files, I lose code formatting/styling and auto-completion. `cake bake` is doing 80% of the work, however, the 20% is exaggerated due the aforementioned workflow issues. By using `.php` I regain the power of pretty code. – jtrumbull Feb 24 '15 at 16:57
  • [Salines](http://stackoverflow.com/users/1127933/salines): Is your answer to write my own `bake` script? – jtrumbull Feb 24 '15 at 16:59

1 Answers1

1

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.

Salines
  • 5,674
  • 3
  • 25
  • 50