PhpStorm and Laravel
Hi All,
Brand new PhpStorm user here :)
I'm developing a few apps using the Laravel framework, and the completion is not working at all :( It's probably just me.
I'm wondering if there's something special I need to do to make it read the laravel files to be able to use them as a completion source.
Eg.
There's several classis that get used statically, so when I type: Route:: i would expect the members/properties etc to show up, but it just says: Undefined class Route.
Any help or feedback would be much appreciated.
Cheers.
Please sign in to leave a comment.
Hi Matt,
Could you please provide a link for that framework (download link) as well as some basic and very simple example project to look into?
Heya,
Laravel is available from: Download link is top right of the front page @ http://laravel.com/
There's a demo app from an earlier version (same problem though) available here: https://github.com/davzie/Laravel-Bootstrap
Cheers.
Hi Matt,
It's the class aliases in the config file that are the problem. There's a Laravel forum thread about it here:
http://forums.laravel.com/viewtopic.php?id=13
And more recently here:
http://forums.laravel.com/viewtopic.php?id=742
The 'gist' of which is that you need to provide PhpStorm with a file in the project that it can parse for class references, but you will never need to load because of the aliases.
Thanks for that, i combined everything in those posts and updated a little and it's nearly all working now :)
The only thing that's not working correctly is absence of suggestions and false flagging when using the classes like this here on line 54 (the title, url_title, etc, properties). Don't think there'd be a quick fix for that though.
So .. framework itself is namespace-based .. but the actual code of app does not use namespaces (have not digged into it much -- but somehow it finds correct classes during runtime). So .. instead of properly inserting use
line where such class will be used (as required per namespaces specs), you just by-passing it by declaring some fake classes ... Well -- whatever -- as long as it works and you are happy.It is not "false flagging" -- you are expecting PhpStorm to discover your dynamic fields (created at runtime) and issue no warning. How should I know for sure if that is indeed valid field and not some typo? Same for PhpStorm.
There are multiple "fixes" for that:
1. Manually declare such variable as instance of stdClass. Your particular example (line 53):
The idea is -- unknown fields on variables of stdClass will not be marked as undefined (no warnings). No code suggestion (code completion) for such dynamic fields will be available.
2. Relax inspection a bit (still no code completion for such fields) -- Settings | Inspections | PHP | Undefined | Undefined field --> Downgrade severity if __magic methods are present in class
This will be applied to whole project (Unless you define custom scopes and configure this inspection differently for each scope). Such unknown fields still will be highlighted, but with lower severity/not-so-visible (not an error/warning, just notice).
3. (The most proper/recommended/cross-IDE-safe way IMO) Define such fields in advance using @property syntax -- code completion will be available. Your particular example
File: \application\models\news.php
Just in case also see: https://gist.github.com/2042822
I am unable to get this to work properly with PHPStorm 5.0.1. I've put the ide_helper.php file in my project root but it's not working.
RESOLVED: I used a different ide_helper.php file.
Can you share your directory structure and the content of the ide_helper.php?
I'm on pS 5 and it works fine, by the was I have mine named "_IDE_HELPER.php"
I created a folder called ide_helper in the project root and placed the ide_helper.php file in there. I then included the ide_helper folder in the PHP include path. Everything appears to be working as expected now.
I have been messing with CodeIgniter for the past couple of days but found Laravel and wanted to start playing around with it. It seems that it has a much more rich feature set.
Laravel is great, and you can always get great help from the community IRC #laravel
Yes! It seems great thus far!
If someone's still interested in a helper file - see this GitHub repository. It works just fine and can be integrated as an external library.