I have a controller in CakePHP 2.2 application.
I use PhpStorm 4.0.1 as IDE.
In MyController.php file I declare this:
/**
* #property MyUtilComponent $MyUtil
*/
Inside my controller, when I write $this-> I can select "MyUtilComponent" from drop down list.
But when I write $this->MyUtilComponent-> no function name option comes to select.
When I write $this->MyUtil->addThis(); and then click to addThis word and "Go to declaration", then PhpStorm goes to method's declaration successfully.
What should I do more to get function names autocompletion ?
Note: The behaviour is same for the core components.
Update your PHPStorm. Version 5.0.4 is currently released and works the way you want it.
Related
I've created new project using PhalconPHP 3.1.2. Everything works fine, but I have problem with IDE. In PhpStorm I've added ide/stubs/Phalcon from phalcon-devtools 3.1.2 as external libraries to dispose of warnings and errors.
But there is still one problem: in app/config/router.php (standard catalog structure created by devtools) I got line $router = $di->getRouter(); (also created by devtools) with warning: Method getRouter not found in Phalcon\Di\FactoryDefault.
There is no method in this class indeed: https://github.com/phalcon/phalcon-devtools/blob/3.1.x/ide/stubs/Phalcon/di/FactoryDefault.php -> https://github.com/phalcon/phalcon-devtools/blob/3.1.x/ide/stubs/Phalcon/Di.php
Now I don't have autocomplete of router's methods and this is problem for me. Did I do something wrong?
First of all -- I'm not familiar with Phalcon. These are my comments based on general PHP/PhpStorm experience.
So .. if you look at that PHPDoc in the last link you gave (stubs for Di.php) you will notice the code example there that has $request = $di->getRequest();.
If you just copy-paste that whole sample you will get the same "method not found" error ... as getRquest() is transformed at run time via magic __get() method.
The possible solution here is to create your own stub for your $di:
Create new class that will extend original Di, e.g.
class MyDi extends \Phalcon\Di
Add all those getRoute() / getRequest() etc methods there (could be real methods with empty bodies as in Phalcon's stub files .. or via #method PHPDoc tag)
Place such file anywhere in the project -- it will be used by IDE only.
When you are using your $di -- typehint it with your class, e.g.
/** #var \MyDi $di */
$di = new Di();
In the above code during runtime $di will be an instance of Di but for PhpStorm during development it will be MyDi so all type hints are in place.
As possible alternative -- instead of using magic via $di->getRoute() .. try $di->getShared('route') or similar.
If you use PhpStorm's Advanced Metadata functionality it will allow to get correct type based on parameter value.
$di->getRouter() is magic method, Phalcon\Di implements __call method and it gets router service this way if you use getRouter().
If you want you can use PHPStorm metadata and use $di->get() https://www.google.pl/search?client=opera&q=phpstorm+metadata&sourceid=opera&ie=UTF-8&oe=UTF-8
in a Yii Application in PHPStorm i have the following Code:
$datasource = Yii::app()->someComponent;
PHPStorm is now not able to find the definition of method parameters in autocomplete, if i write
$datasource->aMethod(
Is there a way to tell phpstorm the source in order to have a working autocomplete?, e.g.
// #definition components/SomeComponent.php
$datasource = Yii::app()->someComponent;
Thanks,
markus
You could use a PHP Doc comment to tell PHPStorm which type the var has.
/** #var SomeClassName $datasource */
$datasource = Yii::app()->someComponent;
There's better solution. One which makes PhpStorm able to assign Yii::app()->someComponent to class for entire project.
Put in CAplication's php doc (above class):
/**
* #property Someclass $someComponent.
*/
Solved with one line of code. It works with PhpStorm 9.0, haven't tested earlier versions.
it's a bit boring to adding this in each ctp files with phpStorm :
/** #var Class $this */
I can not find a way to set globally the variable "$this" to the View class in ctp files, is it possible ?
AFAIK that's not possible (a PHPStorm plugin could of course add that functionality).
You could report this as an enhancement request for the CakePHP bake shell, having this added automatically to the baked view templates wouldn't hurt.
For better cross IDE compatibility it should however probably better be in
/* #var $this Type */
format.
CakePHP 2.x > https://github.com/cakephp/cakephp/issues
CakePHP 3.x > https://github.com/cakephp/bake/issues
I use Kohana 3.x as my Webapplication-Framework (which uses the MVC pattern) and use Propel as my ORM. Within my Controller I create an object that represents the profile that owns the current session:
$this->currentProfile = ProfileQuery::create()->findPK($profileId);
I pass the object to the views, that I use:
View::set_global('myProfile', $this->currentProfile); // c
Now I can use the object "myProfile" within my Views. But the problem is, that within this views, neither Netbeans nor Eclipse know the class of the object. So I cant use Intellisense anymore (which was one of the key-features for using Propel in the first place). So please help me: How can I tell Eclipse and/or Netbeans of which class my object "myProfile" is?
Netbeans solution: put this at the beginning of your template: /* #var $myProfile Profile */
Or: type vdoc and press tab.
When using Zend Studio to write views for a MVC framework, is there any way of having those variables autocomplete, perhaps using PHPdoc?
For example, I set a variable in a view called $cart which is an instance of my ShoppingCart class. When I type "$cart->", I'd like the IDE to pop up with all of the objects properties.
in Netbeans it is possible to do the following:
/* #var $var Class */
not sure if it works in eclipse.