Facilitation in PHP projects

Asked

Viewed 1,028 times

14

I work with PHP using Sublime Text and would like something similar to what it is in Eclipse. For example:

In Eclipse I can open exactly where the method was declared. In Sublime Text I did not find any similar option, which I use the shortcut CTRL + mouse click to open method declarations and everything else.

Sublime Text has some option to make my project easier to navigate, to check the method/function statements?

  • By default in Sublime, if you hold your mouse over the method name or variable it will display a popup with its declaration path, just click on the path and you’re done.

3 answers

13

Most of the content here "maybe" applies only to Sublime Text 3, please note that Sublime Text 2 was last updated on 8 of July 2013

For PHP as for other languages the plugin that works a lot is Codeintel, it uses the autocomplete while typing, so it doesn’t need commands. It recognizes custom functions, classes and namespaces (created in your project), even if it’s in a different file.

  1. Install the Sublimecodeintel Preferences > Package Control > Install Package

  2. Typo SublimeCodeIntel, and select it to install

  3. Install Phpintel Preferences > Package Control > Install Package

  4. Typo PhpIntel, and select it to install

Now you should select the folder of your project and drag it to Sublimetext, like this:

projeto no sublimetext

Now browse through the sublime itself in the project files, open any file and press Ctrl+S, Codeintel will take a while the first time, but will generate in your project folder another folder called .phpintel, it contains a mapping and caches of your classes, every time you use Ctrl+S he’ll update this, then just test:

Classes customizadas

Note that the namespace and class are not native, although it recognizes PHP natives as well.


Other tips

Other interesting settings that you can take into consideration is to edit Settings, go to Preferences > Settings, will open a window with two documents, edit only the right, follow some settings you can use:

Removes unnecessary spaces when saving:

"trailing_spaces_trim_on_save": true, 

Swap Tabs for spaces:

"translate_tabs_to_spaces": true,

Use Tabs as 4 spaces, you can adjust here:

"tab_size": 4,

Shows the encoding of the current file in the Sublimetext footer, helps avoid many headaches:

"show_encoding": true,

Line breaks use only LF:

"default_line_ending": "unix",

Shows what type of "new line" you use, for example: Unix (if the lines in the document end in LF) or Windows (if the lines in the document end in CR LF):

"show_line_endings": true,

Add line break at the end of the document if necessary (of course this is optional):

"ensure_newline_at_eof_on_save": true,

It must look like this:

{
    "always_show_minimap_viewport": true,
    "bold_folder_labels": true,
    "font_size": 11,
    "highlight_line": true,
    "ignored_packages":
    [
        "Vintage"
    ],
    "indent_guide_options":
    [
        "draw_normal",
        "draw_active"
    ],
    "line_padding_bottom": 3,
    "line_padding_top": 3,
    "overlay_scroll_bars": "enabled",
    "show_encoding": true,
    "tab_size": 4,
    "trailing_spaces_trim_on_save": true,
    "translate_tabs_to_spaces": true,
    "show_encoding": true,
    "show_line_endings": true,
    "ensure_newline_at_eof_on_save": true,
    "word_wrap": true
}

Extra

Spell checker, there is no relation, but a spell checker can help avoid constraints sometimes, in case you can manually install it, which can be something very complex, I even tried to download the .dic of Libreoffice and gave problem with Unicode, so I ended up copying .dic that was in the Firefox folder, but this is a bit complicated, so I’ll tell you from the same repository, select the preferred language on https://github.com/titoBouzout/Dictionaries and download . dic and . Aff, for example:

Open the package folder, if it’s Linux or Mac:

  • ~/.config/sublime-text-3/Packages

If it’s Windows maybe it’s the folder like this SublimeText\Data\Packages\

Create a folder called Portuguese for example and copy both files in it, you may have to close the sublime and open again, so go to View > Dictionary and see if it shows up Portuguese, or you can point to Settings as well, like this:

"dictionary": "Packages/Portuguese/Portuguese (Brazilian).dic",

And enable the spell checker permanently:

"spell_check": true,

It should look something like this:

{
    "always_show_minimap_viewport": true,
    "bold_folder_labels": true,
    "dictionary": "Packages/Portuguese/Portuguese (Brazilian).dic",
    "font_size": 11,
    "highlight_line": true,
    "ignored_packages":
    [
        "Vintage"
    ],
    "indent_guide_options":
    [
        "draw_normal",
        "draw_active"
    ],
    "line_padding_bottom": 3,
    "line_padding_top": 3,
    "overlay_scroll_bars": "enabled",
    "show_encoding": true,
    "spell_check": true,
    "tab_size": 4,
    "trailing_spaces_trim_on_save": true,
    "translate_tabs_to_spaces": true,
    "show_encoding": true,
    "show_line_endings": true,
    "ensure_newline_at_eof_on_save": true,
    "word_wrap": true
}

2

I work with Sublime Text too. In the version I use, the 3 (yours is probably the same), just hover over a function and wait 1 to 2 seconds that a small pop-up with a list of files containing the function appears on the cursor. If Sublime doesn’t find any files with this function it doesn’t appear. I didn’t go after configuring it, but maybe I have something for it. But as far as I know it only works with functions.

2

  • All the plug-ins I tested didn’t work properly. Sublimecodeintel was giving direct timeout when I was trying to open where the function was declared. Phpintel we tested as a team here, but it didn’t even work. We tested with other shortcuts, reconfigured and nothing worked. Does anyone have any more ideas? It really matters to me.

  • 1

    @Guilhermenass I installed recently and there were no problems, Phpintel as I explained in the answer only works if you have Codeintel, step by step ideas are all in the answer I formulated, if the timeout is occurring it may be your network that has some lock or download problem.

  • Got it @Guilhermenascimento... I’m using Sublime Text 2, it works also usually right?

  • @Guilhermenass never used Sublimetext2 I see no reason to use 2 and 3 is already so good.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.