課程
/后端開發
/PHP
/PHP開發APP接口
獲取緩存不成功呢
2015-03-30
源自:PHP開發APP接口 3-1
正在回答
請附上代碼
Mr_Blue_001
<?php
????//調用文件操作類?? ?// include "./resu.class.php";?? ?//error_reporting(0);?? ?include "file.php";?? ?$data= array(?? ??? ?'id'=>1,?? ??? ?'name'=>'singwa',?? ??? ?'type'=>array(4,5,6),?? ??? ?'test'=>array(1,45,67=>array(1,'45698'),),?? ?);?? ?// resu::show(200,'success',$data,'json');?? ?$file = new File();?? ?if($file->cacheData('index_mk_cache')){?? ??? ?var_dump($file->cacheData('index_mk_cache'));exit();?? ??? ?echo "seccess";?? ?}else{?? ??? ?echo 'error';?? ?}
<?php?? ??? ?class File{?? ??? ?private $_dir;?? ??? ?const EXT = '.txt';?? ??? ?public function __construct() {?? ??? ??? ?$this->_dir = dirname(__FILE__) . '/files/';?? ??? ?}?? ??? ?public function cacheData($key,$value,$path=''){?? ??? ??? ?$filename = $this->_dir? . $key . self::EXT;?? ??? ??? ?if($value != '') { // 將value值寫入緩存?? ??? ??? ??? ?/*if(is_null($value)) {?? ??? ??? ??? ??? ?return @unlink($filename);?? ??? ??? ??? ?}*/?? ??? ??? ?$dir = dirname($filename);?? ??? ??? ??? ?if(!is_dir($dir)) {?? ??? ??? ??? ??? ?mkdir($dir, 0777);?? ??? ??? ??? ?}?? ??? ??? ??? ?return file_put_contents($filename,json_encode($value));?? ??? ??? ?}?? ??? ??? ?if(!is_file($filename)){?? ??? ??? ??? ?return false;?? ??? ??? ?}else{?? ??? ??? ??? ?return json_decode(file_get_contents($filename),true);?? ??? ??? ?}?? ??? ?}?? ?}???
舉報
APP通信接口技術,不得不掌握的法寶,學完之后你會受益良多
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號-11 京公網安備11010802030151號
購課補貼聯系客服咨詢優惠詳情
慕課網APP您的移動學習伙伴
掃描二維碼關注慕課網微信公眾號
2015-03-30
請附上代碼
2015-03-30
<?php
????//調用文件操作類
?? ?// include "./resu.class.php";
?? ?//error_reporting(0);
?? ?include "file.php";
?? ?$data= array(
?? ??? ?'id'=>1,
?? ??? ?'name'=>'singwa',
?? ??? ?'type'=>array(4,5,6),
?? ??? ?'test'=>array(1,45,67=>array(1,'45698'),),
?? ?);
?? ?// resu::show(200,'success',$data,'json');
?? ?$file = new File();
?? ?if($file->cacheData('index_mk_cache')){
?? ??? ?var_dump($file->cacheData('index_mk_cache'));exit();
?? ??? ?echo "seccess";
?? ?}else{
?? ??? ?echo 'error';
?? ?}
2015-03-30
<?php
?? ?
?? ?class File{
?? ??? ?private $_dir;
?? ??? ?const EXT = '.txt';
?? ??? ?public function __construct() {
?? ??? ??? ?$this->_dir = dirname(__FILE__) . '/files/';
?? ??? ?}
?? ??? ?public function cacheData($key,$value,$path=''){
?? ??? ??? ?$filename = $this->_dir? . $key . self::EXT;
?? ??? ??? ?if($value != '') { // 將value值寫入緩存
?? ??? ??? ??? ?/*if(is_null($value)) {
?? ??? ??? ??? ??? ?return @unlink($filename);
?? ??? ??? ??? ?}*/
?? ??? ??? ?$dir = dirname($filename);
?? ??? ??? ??? ?if(!is_dir($dir)) {
?? ??? ??? ??? ??? ?mkdir($dir, 0777);
?? ??? ??? ??? ?}
?? ??? ??? ??? ?return file_put_contents($filename,json_encode($value));
?? ??? ??? ?}
?? ??? ??? ?if(!is_file($filename)){
?? ??? ??? ??? ?return false;
?? ??? ??? ?}else{
?? ??? ??? ??? ?return json_decode(file_get_contents($filename),true);
?? ??? ??? ?}
?? ??? ?}
?? ?}???