2015-05-01 15 views
7

इसलिए मैंने लैरवेल 4 से 5 तक जाने का फैसला किया जो मुझे 1-2 दिनों तक ले गया क्योंकि मुझे मुश्किल से पता था कि संक्रमण कैसे करें। मेरे ऐप के लिए अपग्रेड करते समय मुझे जेसन पेजिनेशन के साथ एक छोटी सी समस्या आई।लैरवेल 5 कैश/अंकन अंक

इस कोड क्या अनुमति देता है एक PageQuery पृष्ठवार जा करने के लिए किया जाता है के माध्यम से KnockoutJS

/** 
* Builds paginate query with given parameters. 
* 
* @param array $params 
* @param integer $page 
* @param integer $perPage 
* 
* @return array 
*/ 
public function buildPaginateQuery(array $params, $page = 1, $perPage = 15) 
{ 
    $query = $this->model; 

    $query = $this->appendParams($params, $query); 

    $count = (new Cache)->remember('count', '2000', function() use ($query){ 
     return $query->count(); 
    }); 

    $totalPages = $count/$perPage; 

    $query = $query->skip($perPage * ($page - 1))->take($perPage); 

    $query = $query->order(isset($params['order']) && $params['order'] ? $params['order'] : null); 

    //$query = $query->cacheTags(array($this->model->table, 'pagination'))->remember(2000); 

    $query = (new Cache)->remember(array($this->model->table, 'pagination'), '2000', function() use ($query){ 
     return $query; 
    }); 

    return array('query' => $query, 'totalPages' => $totalPages, 'totalItems' => $count); 
} 

जो अंततः इस स्क्रीनशॉट में इस त्रुटि के लिए नेतृत्व TaggedFile Cache Error

त्रुटि ऊपर कोड और इस कोड पर ले जाने वाली विशेष रूप से

/** 
* Get the full path for the given cache key. 
* 
* @param string $key 
* @return string 
*/ 
protected function path($key) 
{ 
    $parts = array_slice(str_split($hash = md5($key), 2), 0, 2); 
    $path = $this->directory() . '/'.join('/', $parts).'/'.$hash; 

    //unset the tags so we use the base cache folder if no 
    //tags are passed with subsequent call to the same instance 
    //of this class 
    //$this->tags = array(); 

    return $path; 
} 

इम एक कस्टम कैश ड्राइवर TaggedFile कहा जाता है का उपयोग कर। यह एल 4 में ठीक काम करता था लेकिन त्रुटियों में आया क्योंकि कैश एलियास के भीतर कुछ फाइलें हटा दी गई थीं। StoreInterface की तरह। क्या मुझे इसके लिए कुछ मदद मिल सकती है? अगर आपको कुछ भी पोस्ट करने की ज़रूरत है तो मैं करूंगा।

अधिक सामग्री:

इससे पहले कि मैं इस प्रयोग किया जाता global.php में taggedFile ड्राइवर रजिस्टर करने के लिए:

Cache::extend('taggedFile', function($app) 
{ 
    return new Illuminate\Cache\Repository(new Lib\Extensions\TaggedFileCache); 
}); 

मैं कहाँ वास्तव में इस डाल करने के लिए पता नहीं है। क्या किसी के बराबर पता है? मैं इसे AppServiceProvider में डालने की कोशिश की लेकिन एक त्रुटि कह आया:

Call to undefined method Illuminate\Support\Facades\Cache::extend() 

यह L4 में काम करता था तो मैं स्वयं को खोजने के लिए कि समस्या क्या था ....

यह विक्रेता फ़ोल्डर में जाने का फैसला किया केवल था: getFacadeAccessor (जो एल 4 ने केवल काम किया था लेकिन काम किया था) इसलिए मैंने getFacadeAccessor का उपयोग करने का निर्णय लिया और यह काम किया, लेकिन मुझे नहीं पता कि यह समाधान था या नहीं।

उत्तर

0

आपने देखा के रूप में आप एक $ कुंजी मान के रूप में एक सरणी से गुजर रहे हैं, सबसे सुरक्षित तरीका के साथ

$parts = array_slice(str_split($hash = md5(json_encode($key)), 2), 0, 2); 

नायब कोड

$parts = array_slice(str_split($hash = md5($key), 2), 0, 2); 

को बदलने के लिए होगा: मुझे यकीन है कि नहीं कर रहा हूँ कौन-सा संस्करण PHP का आप चल रहे हैं, लेकिन json_encode (...) सामान्य रूप से तेज़ है तो serialize (...)

संबंधित मुद्दे