---- file 1 ----
use Models\Post;
class A
{
public function fct() {
Post::all();
}
}
---- file 2 ----
class B extends A {
}
如何在 B类中使用Post而无需再次写入使用Models \ Post 。
答案 0 :(得分:0)
尝试这种方式
---- file 1 ----
use Models\Post as Post;
class A
{
public $post;
// instantiate in __construct and store it to a public or protected variable
public function __construct() {
$this->post = new Post;
}
public function fct() {
$this->post->all();
}
}
---- file 2 ----
class B extends A {
}