我正在尝试使用其PHP客户端https://iflychat.com/installation/php-chat-client与Symfony一起运行iFlyChat ,我已经使用composer成功安装了该客户端。
我为代码创建了扩展名:
<?php
namespace DW\UserBundle\Twig;
use DW\UserBundle\Service\UserService;
use Iflylabs\iFlyChat;
class ChatExtension extends \Twig_Extension
{
/**
* @var UserService
*/
private $userService;
/**
* @var string
*/
private $appId;
/**
* @var string
*/
private $apiKey;
/**
* @param UserService $userService
* @param string $appId
* @param string $apiKey
*/
public function __construct(UserService $userService, string $appId, string $apiKey)
{
$this->userService = $userService;
$this->appId = $appId;
$this->apiKey = $apiKey;
}
/**
* @return array
*/
public function getFunctions()
{
return [
new \Twig_SimpleFunction("chat", [$this, "chat"])
];
}
public function chat()
{
$iflyChat = new iFlyChat($this->appId, $this->apiKey);
echo $iflyChat->getHtmlCode();
}
/**
* @return string
*/
public function getName()
{
return 'chat_extension';
}
}
但我得到一个错误:
尝试从名称空间“ IFlyLabs”加载类“ iFlyChat”。您是否忘记了另一个名称空间的“使用”语句?
我需要用自动装带器做什么吗?我一直在这里查看registerPrefixes ,但是对于Symfony3.2来说已经不存在了。
这是因为文件名与类名不匹配,它是iflychat.php
在类为时安装的iFlyChat
。重命名该文件即可iFlyChat.php
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句