Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Language IDEs » PHP Development Tools (PDT) » Code completion...
Code completion... [message #80878] Sat, 27 September 2008 03:44 Go to next message
Eugen is currently offline EugenFriend
Messages: 5
Registered: July 2009
Junior Member
I don't know if this was brought up before, or what its referred to, but I
work with cakePHP a lot, and I run into a problem that I don't get code
completion on custom Models when I reference them from the controller.

For example I will have my userModel.php

class MyModel extends AppModel {
var $name;

}

and in my userController.php I will have

class UserController extends AppController {
echo $this->MyModel->save($this->form(data);

}


$this->MyModel->[code completion jumps in]
does anyone have a glue how to make this work?
Re: Code completion... [message #80883 is a reply to message #80878] Mon, 29 September 2008 00:08 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: eclipsenews.20.epm.spamgourmet.com

The only way PDT can tell what type $this->MyModel is, is if you write a
PHPDoc comment.

Given that it's cakephp and the mymodel object is created via some
hidden runtime voodoo, there's no way for PDT to tell what type it is.

You can try adding a doc comment identifying it to your controller,
hopefully cake will play nice with that.


Eugen wrote:
> I don't know if this was brought up before, or what its referred to, but
> I work with cakePHP a lot, and I run into a problem that I don't get
> code completion on custom Models when I reference them from the controller.
> For example I will have my userModel.php
>
> class MyModel extends AppModel {
> var $name;
>
> }
>
> and in my userController.php I will have
> class UserController extends AppController {
> echo $this->MyModel->save($this->form(data);
>
> }
>
>
> $this->MyModel->[code completion jumps in]
> does anyone have a glue how to make this work?
>
Re: Code completion... [message #83387 is a reply to message #80883] Tue, 11 November 2008 12:05 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: michael.zend.com

Not exactly. If you have an assignment to this variable in your class
constructor it will be taken into account also.
For example:

class B {
function foo() {
}
}

class A {
var $v;
function __construct() {
$this->v = new B();
}
}

$a = new A();
$a->v->foo(); // here foo() is proposed by Code Assist

"Tom Walter" <eclipsenews.20.epm@spamgourmet.com> wrote in message
news:48E01C8B.3060807@spamgourmet.com...
> The only way PDT can tell what type $this->MyModel is, is if you write a
> PHPDoc comment.
>
> Given that it's cakephp and the mymodel object is created via some hidden
> runtime voodoo, there's no way for PDT to tell what type it is.
>
> You can try adding a doc comment identifying it to your controller,
> hopefully cake will play nice with that.
>
>
> Eugen wrote:
>> I don't know if this was brought up before, or what its referred to, but
>> I work with cakePHP a lot, and I run into a problem that I don't get code
>> completion on custom Models when I reference them from the controller.
>> For example I will have my userModel.php
>>
>> class MyModel extends AppModel {
>> var $name;
>>
>> }
>>
>> and in my userController.php I will have
>> class UserController extends AppController {
>> echo $this->MyModel->save($this->form(data);
>>
>> }
>>
>>
>> $this->MyModel->[code completion jumps in]
>> does anyone have a glue how to make this work?
>>
Re: Code completion... [message #83658 is a reply to message #83387] Thu, 13 November 2008 13:13 Go to previous messageGo to next message
Romain Riviere is currently offline Romain RiviereFriend
Messages: 2
Registered: July 2009
Junior Member
Hello there,

Michael Spector wrote:

> Not exactly. If you have an assignment to this variable in your class
> constructor it will be taken into account also.
> For example:

> class B {
> function foo() {
> }
> }

> class A {
> var $v;
> function __construct() {
> $this->v = new B();
> }
> }

> $a = new A();
> $a->v->foo(); // here foo() is proposed by Code Assist

This is fine as long as you are not using Singletons. Consider this :

class B {
private $instance ;
public static function GetInstance() {
if(empty(self::$instance)) {
self::$instance = new B ; }
return self::$instance ;
}
function foo() {
}
}

class A {
var $v;
function __construct() {
$this->v = B::GetInstance();
}
}

$a = new A();
$a->v->foo(); // No Code Assist here

In that case, adding a PHPDoc block for "var $v" is the only way (AFAIK)
to get Code Assist to work.
Adding a PHPDoc block to the GetInstance static method in order to specify
the return type also helps but only inside the class context.
Re: Code completion... [message #83672 is a reply to message #83658] Thu, 13 November 2008 14:06 Go to previous messageGo to next message
Eclipse UserFriend
Originally posted by: michael.zend.com

Such examples can become a use cases for our Type Inference engine that can
be improved.
Thanks!

"Romain Riviere" <romain.riviere@gmail.com> wrote in message
news:2c5ced46408675a79299ca9818d638e2$1@www.eclipse.org...
> Hello there,
>
> Michael Spector wrote:
>
>> Not exactly. If you have an assignment to this variable in your class
>> constructor it will be taken into account also.
>> For example:
>
>> class B {
>> function foo() {
>> }
>> }
>
>> class A {
>> var $v;
>> function __construct() {
>> $this->v = new B();
>> }
>> }
>
>> $a = new A();
>> $a->v->foo(); // here foo() is proposed by Code Assist
>
> This is fine as long as you are not using Singletons. Consider this :
>
> class B {
> private $instance ;
> public static function GetInstance() {
> if(empty(self::$instance)) {
> self::$instance = new B ; }
> return self::$instance ;
> }
> function foo() {
> }
> }
>
> class A {
> var $v;
> function __construct() {
> $this->v = B::GetInstance();
> }
> }
>
> $a = new A();
> $a->v->foo(); // No Code Assist here
>
> In that case, adding a PHPDoc block for "var $v" is the only way (AFAIK)
> to get Code Assist to work.
> Adding a PHPDoc block to the GetInstance static method in order to specify
> the return type also helps but only inside the class context.
>
Re: Code completion... [message #83688 is a reply to message #83672] Thu, 13 November 2008 14:32 Go to previous message
Romain Riviere is currently offline Romain RiviereFriend
Messages: 2
Registered: July 2009
Junior Member
Michael Spector wrote:

> Such examples can become a use cases for our Type Inference engine that can
> be improved.
> Thanks!

Anytime :) That's the least I could do !
Previous Topic:Validate Goes Bad w/No Changes
Next Topic:java.lang.IllegalArgumentException
Goto Forum:
  


Current Time: Thu Apr 25 12:45:25 GMT 2024

Powered by FUDForum. Page generated in 0.03110 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top