Autocompleting MVC View Variables in Eclipse PDT/Zend Studio - php

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.

Related

PhpStorm 2021.3.2 Settings

I am new using PhpStorm. Previously I used Visual Studio Code and Sublime Text 3/4, however with PhpStorm it is much more convenient to work with PHP and I am happy with the IDE.
I have customized the style of the code according to my needs and the convention of the Framework I am working with. The problem arises when doing a cleanup and/or reformatting of the code: when this happens, the protected and public methods get mixed up. I will try to explain it as best as possible.
For example: if I have a protected method named getPath that is called in one or more public methods at the beginning of the class, by convention this method should be at the end of the class along with the private methods, but then if I set another public method that does not use the getPath method, getPath is placed on top of the new public method. I KNOW! It doesn't seem to be a problem, but when you follow strict convention rules of a framework or a personal convention, this ends up being very important.
In my case, I'm extremely clean and tidy in my code, but I haven't been able to configure the IDE to keep methods private and protected at the end of the class.
I would like to know if someone can help me configure the IDE to solve the problem and if possible I would like the magic methods (__call, __callStatic, __sleep, __get) to be kept at the end of everything.
I am using PhpStorm 2021.3.2.

Completion with cakephp ctp file in PhpStorm

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

PhpStorm code auto completion in CakePHP

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.

PHP: How to tell Eclipse/Netbeans that an object is of a certain class, to enable Intellisense

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.

In Zend studio, how to tell the ide the type of a variable, so I have auto completion?

In php we use includes. So variables defined in one file and then their scope spans included files too.
Zend studio has no idea how to get the type of the variable I am using inside an included file, this is very annoying when the variable type is a big class.
Is there a way to hint the ide about variable types? in included files?
Here is a manual entry of the very old Zend Studio 5.
/* #var $router \Core\Router */
$router = Registry::get("router");
$router->route();
This feature is also works in new Zend Studio including version 10!
I have an article on some code completion tips Zend Studio and PDT Code Completion Tips that might help. However, it is a good idea to try and limit the variables that required from other files. It can quite easily make for difficult to maintain code.
foreach($A as $AnInstance)
/*#var MyClass $AnInstance*/
$AnInstance->doSomething();

Categories