Check these github repositories, I have found then and they are so good for work with php and cakephp
Best configuration and parameters for ctags in a CakePHP project
-
24-06-2022 - |
Frage
What is the best configuration and parameters for ctags
in a CakePHP project?
I want to be able to auto-complete ctp
files, Components
, Behaviours
, Models
and Helpers
?
Lösung
Andere Tipps
This solution requires 1 line in your .ctags
file and two lines in your .vimrc
file, so it's fairly minimal.
tl;dr
.ctags
:
--langmap=php:+.ctp
.vimrc
:
# Controller -> Component
map <leader>t yiw<cr>:tag /^<C-R>"<CR>
# View -> Helper
map <leader>h yiw<cr>:tag /^<C-R>"Helper<CR>
Add Views to your tags
This solution is mostly for jumping between files. I'll try and add auto-completion at a later date.
Add this to your ~/.ctags
options file to include CakePHP views as PHP files:
--langmap=php:+.ctp
Then I'm assuming you've done ctags -R .
at the root of your project (that's what I've done at least). This out of the box should pick up PHP syntax and class definitions.
Auto-completion (general)
I found the auto-completion (omni-completion from Ctrl+XCtrl+O) doesn't work very nicely with PHP, e.g. if I type $this->
and then try to auto-complete it doesn't find any tags.
The fix for this was to use install phpcomplete.vim. This will find methods within your class.
However that won't auto-complete connected models.
Models
By default ctags should work for all Controller -> Model jumping as the Model name is the same as the class name.
Behaviors
These again should be fine as you don't specify the name of the behavior you just have the method name which depending on how independent the name is it should get found - or at least it will be in the list of tags.
Components
There's no direct way of mapping these, I couldn't see a way of mapping them through the ctags --regex
options. ctags recognises that they are classes but doesn't know the xxx
-> xxxComponent
mapping.
However there is one slight trick. You can do a tag search on the beginning of the class name (source)
:tag /^Email
will find
class EmailComponent
You can then map this in your .vimrc
map <leader>t yiw<cr>:tag /^<C-R>"<CR>
This copies the word that you've got the cursor over and then pastes it into the tag command and executes it. My leader is set to ,
, so I can type ,t
and it takes me to the corresponding component under the cursor.
Helpers
Ok, another slight hack in the .vimrc file:
map <leader>h yiw<cr>:tag /^<C-R>"Helper<CR>
Using ,h
, this will jump you from $html->...
to
class HtmlHelper extends AppHelper {
But it doesn't work for functions inside e.g. if your cursor is over script
in $html->script
, it will not take you to the HtmlHelper
script
method. So it's a work in progress.