我有两个php文件,一个视图(内容)和一个Object(Receiver)。
content.php
<?php
include '../model/Receiver.php';
$receiver = new Receiver;
Receiver.php
<?php
namespace app\model;
use app\model\Invoice;
class Receiver{
public function __construct(){
$Invoice = new Invoice;
}
}
项目结构
.
├── app
│ ├── model
└── Receiver.php
│ └── view
└── content.php
运行content.php后,我收到此错误。
PHP致命错误:未捕获错误:类&#39;接收器&#39;找不到 C:\ MAMP \ htdocs中\ invoiceexpress \应用\视图\ content.php:5
我无法找出原因。有人可以帮忙吗?
答案 0 :(得分:1)
因为您通过Receiver
将命名空间添加到namespace app\model;
类。使用new
或使用use
语句时可以使用添加命名空间:
<?php
include '../model/Receiver.php';
use \app\model\Receiver;
$receiver = new Receiver;
或
<?php
include '../model/Receiver.php';
$receiver = new \app\model\Receiver;