[英]Need help in using namespaces with composer autoload
My simple class looks like this: 我的简单类如下所示:
<?php
require_once '../../vendor/autoload.php';
use App\Libraries\user;
class chat{
private $user;
public function __constuct(){
$this->user = new user();
}
public function adduser(){
//userdata is available
$userobj = $this->user->adduser($userdata);
}
}
I am trying to create instance of user class but somehow it's giving me error.Fatal error: Call to a member function adduser() on a non-object in /var/www/app/controller/chat.php on line 14. I have checked in composer's autoload_classmap file and I can see the mapping for user class like: 我正在尝试创建用户类的实例,但不知何故,它给了我error.Fatal错误:在第14行的/var/www/app/controller/chat.php中的非对象上调用成员函数adduser()。已经检查了作曲家的autoload_classmap文件,我可以看到用户类的映射,例如:
'App\\Libraries\\user' => $baseDir . '/app/libraries/User.php',
'App\\Libraries\\DBConnection' => $baseDir . '/app/libraries/Database.php',
I am not sure what is missing here to get an instance of user object in 'chat' class using namespace. 我不确定要使用命名空间在“聊天”类中获取用户对象的实例在这里缺少了什么。
user class: 用户类别:
<?php
use App\Libraries\DBConnection;
class user{
public function __construct(){
$this->db = new DBConnection();
}
public function adduser($user){
//insert operation
}
}
This is odd. 这很奇怪。 I've had a similar issue in the past, unfortunately I don't remember the exact fix...
过去我遇到过类似的问题,很遗憾,我不记得确切的解决方法...
I would check file permissions. 我会检查文件权限。
Try adding an entry in the psr-0 section of composer.json to try a different namespace. 尝试在composer.json的psr-0部分中添加一个条目,以尝试其他名称空间。
If using symfony, check the app-cache. 如果使用symfony,请检查应用程序缓存。
I'll post more if the solution comes back to me. 如果解决方案回到我的身边,我会发布更多信息。 Sorry that I can't be more helpful at this stage.
抱歉,在这个阶段,我帮不上什么忙。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.