1
我通过扩展引导方法来启动我的Laravel
应用程序,其中我有一个检查缓存中的值的小检查点。对于这个我使用Laravel's
自己Illuminate\Foundation
helper function
cache
,但不幸的是我得到和错误,我的应用程序代码是:如何在Laravel中使用Cache辅助函数
<?php
namespace App;
use Illuminate\Foundation\Application as IlluminateApplication;
use LayerShifter\TLDExtract\Extract;
/**
* Extends \Illuminate\Foundation\Application to override some defaults.
*/
class Application extends IlluminateApplication
{
/**
* Is Client.
*
* @var boolean
*/
protected $isClient = false;
/**
* Client secret key.
*
* @var boolean
*/
protected $clientSecret;
/**
* Client ID.
*
* @var boolean
*/
protected $clientID;
/**
* Constructing the class with tenant check
*/
public function __construct($basePath = null)
{
parent::__construct($basePath);
$this->clientCheck();
}
public function clientCheck()
{
if($this->isClient = cache('is_client'))
{
return $this->isClient;
}
else
{
$domainData = $this->getDomainSubDomain();
//Do Check and return the value,
//Set the values
// Cache for one day
$data = //Data which is being recieved
cache(['is_client' => $data], 1 * 24 * 60);
return $data;
}
}
/**
* Get Domain and Sub Domain
*
* @return array
*/
public function getDomainSubDomain()
{
$http_req = php_sapi_name() == 'cli' ? 'noetic.com' : $_SERVER["SERVER_NAME"];
$extract = new Extract();
$result = $extract->parse($http_req);
return array(
"domain" => $result->getHostname() . '.' . $result->getSuffix(),
"subDomain" => $result->getSubdomain()
);
}
}
错误,我越来越:
Fatal error: Uncaught ReflectionException: Class cache does not exist in
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Container\Container.php:729 Stack trace: #0
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Container\Container.php(729): ReflectionClass->__construct('cache') #1
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Container\Container.php(608): Illuminate\Container\Container->build('cache') #2
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Container\Container.php(575): Illuminate\Container\Container->resolve('cache') #3
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Foundation\Application.php(728): Illuminate\Container\Container->make('cache') #4
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(106): Illuminate\Foundation\Application->make('cache') #5
E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Foundation\helpers.php(230): app('cache') #6
E:\ in E:\xamppNew\htdocs\noeticit\vendor\laravel\framework\src\Illuminate\Container\Container.php on line 729
指引我我怎么能做到这一点。
你试过用'app(“cache”)'? –
也许缓存服务尚未包含在内。尝试在控制器中使用该功能,如果这可以正常工作,那么显然问题是应用程序尚未启动缓存方法。 –
@ParantapParashar:缓存正在通过控制器工作,但我的问题是我想在加载应用程序之前进行缓存存储检查,我有不同的环境需要加载相应的不同域,FYI你可以看看在这个应用程序https://github.com/phanan/koel/blob/master/app/Application.php#L88 –