我正在使用codeigniter 2框架编写一个项目,其中doctrine 2 作为使用 eclipse PDT 的 ORM。我想知道是否有办法让自动完成适用于原则 2 实体类(位于 ''应用程序''模型''实体文件夹中的类)我设法让它随便工作一次,所以我知道这是可能的,现在我想知道如何让它始终工作或我做错了什么。
为了清楚起见,假设我们有这个控制器:
class Main extends My_Controller {
function index() {
$casualAccount = $this->doctrine->em->find('Entities'Account' , 1);
$casualAccount-> **AUTOCOMPLETITION NOT WORKING HERE**
$this->load->view('welcome_message.php');
}
}
我们在'models'Entities
有这个模型:
use Doctrine'ORM'Mapping as ORM;
/**
* Entities'Account
*/
class Account
{
/**
* @var integer $id
*/
private $id;
/**
* @var string $Mail
*/
private $Mail;
/**
* @var string $Password
*/
private $Password;
/**
* @var string $Type
*/
private $Type;
/**
* @var string $First_name
*/
private $First_name;
/**
* @var string $Last_name
*/
private $Last_name;
/**
* Get id
*
* @return integer
*/
public function getId()
{
return $this->id;
}
/**
* Set Mail
*
* @param string $mail
* @return Account
*/
public function setMail($mail)
{
$this->Mail = $mail;
return $this;
}
/**
* Get Mail
*
* @return string
*/
public function getMail()
{
return $this->Mail;
}
/**
* Set Password
*
* @param string $password
* @return Account
*/
public function setPassword($password)
{
$this->Password = $password;
return $this;
}
/**
* Get Password
*
* @return string
*/
public function getPassword()
{
return $this->Password;
}
/**
* Set Type
*
* @param string $type
* @return Account
*/
public function setType($type)
{
$this->Type = $type;
return $this;
}
/**
* Get Type
*
* @return string
*/
public function getType()
{
return $this->Type;
}
/**
* Set First_name
*
* @param string $firstName
* @return Account
*/
public function setFirstName($firstName)
{
$this->First_name = $firstName;
return $this;
}
/**
* Get First_name
*
* @return string
*/
public function getFirstName()
{
return $this->First_name;
}
/**
* Set Last_name
*
* @param string $lastName
* @return Account
*/
public function setLastName($lastName)
{
$this->Last_name = $lastName;
return $this;
}
/**
* Get Last_name
*
* @return string
*/
public function getLastName()
{
return $this->Last_name;
}
更新。马尼克斯的评论有点帮助。可以使用以下语法在类中声明一个变量,告诉它将是哪个类:
class Main extends My_Controller {
/**
* @var Entities'Account
*/
var $casualAccount;
....
}
这可能会有所帮助,但它仍然远非自动完成日食应该能够做到的。
让我猜猜我是否理解。我从未使用过 Eclipse PDT,但是当不清楚时,应该在内联变量中使用注释。下面的代码有助于 IDE find()
函数返回哪种类型的 var,因为此函数会动态生成实体。没有返回特定类型。
/**
* @var $casualAccount Entities'Account
*/
$casualAccount = $this->doctrine->em->find('Entities'Account' , 1);
$casualAccount-> **AUTOCOMPLETITION SHOULD WORK AT THIS POINT *
上面的注释告诉 IDE
$casualAccount
是Entities'Account
的类型。
这就是为什么并非总是自动完成可用的原因。看一看:
$this->load->library('Foo');
$this->foo-> /* nothing to show */
自动完成在这里不起作用,因为类引用本身是动态生成的,即使您已经记录了它。