我有一个项目,它是某种MVC模式。在引导类中,我创建了控制器的实例,它创建了视图和模型的实例。但模型是用loadModel方法加载的。然后所有控制器都扩展控制器类。它是这样的:
class boot{
function __construct(){
//some code... exploding url etc
require 'controllers/'.$url[0].".php";
$this->controller = new $url[0];
$this->controller->loadModel($url[0]);
//.....
}
}
class controller{
function __construct(){
$this->view = new view();
}
function loadModel($name){
$modelName = $name."_model"
//....
$this->model = new $modelName();
//....
}
}
class model{
// some code
}
class view{
// some code
}
所以我制作了新的控制器和型号:
class test_model extends model{
function __construct(){
parent::__construct()
}
function alabala(){
some code...
}
function afdfa(){
some code...
}
function asdfadf(){
some code...
}
}
class test extends controller{
function __construct(){
parent::__construct()
}
->here is the problem<-
$this->model->no methods suggestions
}
NetBeans不建议使用test_model
中的任何方法。
PhpDesigner 7和PhpDesigner 8建议所有方法形成任何模型类。我如何设置NetBeans为我提供项目中所有类的所有方法?
问题是,您的IDE在计算属性类型方面只能走这么远。有两种方法可以解决:
class boot {
/* @var $model test_model */
protected $model;
....
}
仔细想想,这可能只是/* $var test_model */
;我不确定,因为我总是使用自定义的getter:
class test extends controller {
public function __construct() {
parent::__construct()
}
public function anotherMethod() {
$this->getTestMode->will offer model suggestions...
}
/**
* Get test_model
*
* @return test_model
*/
public function getTestModel() {
return $this->model;
}
}
是"phpdoc"注释通知IDE返回的类的类型,它会自动选择要提供的正确的类方法和属性集。
此外:总是指定您的访问级别是一种很好的风格,即您的方法和属性是public
、protected
还是private
。的确,默认情况下它们是public
,但如果没有这个说明符,它们看起来更像传统的PHP4,并且新的样式指南(例如PSR-x)采用了显式形式。