使用了下PD的依赖注入,IDE显示正常,但实际运行报错
<?php
namespace app\toadmin\controller;
use common\api\Auth;
use Respect\Validation\Validator as v;
use support\Request;
use DI\Attribute\Inject;
class Log
{
#[Inject]
private Auth $auth;
function getList(Request $request){
$data = v::input(
$request->all(),[
'size' => v::intVal()->length(1, 100)->setName('分页大小'),
'page' => v::intVal()->length(1, 90000)->setName('当前页'),
'keywords' => v::optional(v::StringType())->setName('关键字'),
'start_time' => v::optional(v::dateTime())->setName('开始时间'),
'end_time' => v::optional(v::dateTime())->setName('结束时间'),
]
);
dump($this->auth);
return toTrue($this->auth->getLogList($data));
}
}
#[Inject] found on property app\\toadmin\\controller\\Log::auth but unable to guess what to inject, the type of the property does not look like a valid class or interface name
php8.2
"php-di/php-di": "^7.0",
我的错,已解决,
use common\api\Auth; 应该为 use app\common\api\Auth;
ide创建的时候,省略了app\