0
Phalcon 3でライブラリをコーディングしようとしましたが、Cookiesサービスを呼び出すときにエラーが発生します。Phalcon 3 RuntimeException:メソッドを呼び出しようとしていないオブジェクトを取得しようとしました
誰でも教えてください。
私が手にエラーがある:
Services.phploader.php
$loader->registerDirs(
[
$config->application->controllersDir,
$config->application->modelsDir,
$config->application->incubatorDir.'Mailer/',
$config->application->libraryDir.'gAuth/',
]
)->register();
:
RuntimeException: Trying to call method get on a non-object
私のコードは次であります
$di->setShared('cookies', function() {
$cookies = new Cookies();
$cookies->useEncryption(false);
return $cookies;
});
$di->set('gauth', function(){
$gauth = new gAuth();
return $gauth;
});
authController.php
public function authAction(){
$this->gauth->store();
}
gAuth.php
use Phalcon\Crypt;
use Phalcon\Http\Response\Cookies;
class gAuth
{
public $token;
protected $cookie;
private $secret;
private $crypt;
public function __construct()
{
$this->secret = '************;
$this->crypt = new Crypt();
$this->cookie = new Cookies();
$this->cookie->useEncryption(false);
}
public function storeToken()
{
// here I get the error: Trying to call method get on a non-object
$this->cookie->set('tkn', '***', time() + 3600, '/', null, 'web.com', null)->send();
}
こんにちは、ティモシー。ご回答有難うございます。私はどのようにライブラリ内のサービスにアクセスできるのか分かりません。 gAuth.phpはライブラリディレクトリにあり、loader.phpファイルからロードされていますが、そこにサービスを呼び出そうとするとロードできません。エラーは次のようになります:エラー:ヌルのメンバ関数set()への呼び出し – Infobuscador
あなたは 'Component'のクラスを拡張することも、' Di :: getDefault() - > get( 'cookies ') ' – Timothy
ありがとうございます。それは今働きます! – Infobuscador