Browse Source

commit load and save function

superbee 8 years ago
parent
commit
ce2d40fa92
3 changed files with 69 additions and 44 deletions
  1. 5 5
      .buildpath
  2. 63 39
      application/home/controller/User.php
  3. 1 0
      load/temp.txt

+ 5 - 5
.buildpath

@@ -1,5 +1,5 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<buildpath>
-	<buildpathentry kind="src" path=""/>
-	<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
-</buildpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<buildpath>
+	<buildpathentry kind="src" path=""/>
+	<buildpathentry kind="con" path="org.eclipse.php.core.LANGUAGE"/>
+</buildpath>

+ 63 - 39
application/home/controller/User.php

@@ -1,40 +1,64 @@
-<?php
-namespace app\home\controller;
-
-use think\Controller;
-use app\user\model\UserSkill;
-
-class User extends Controller {
-	
-	private $userModel, $skillModel;
-	
-	public function _initialize(){
-		$this->skillModel = new UserSkill();
-	}
-	
-	public function login()
-	{
-		$data = decode($this->request->post());
-		$this->userModel = new \app\user\model\User(); 
-		
-		$info = $this->userModel->loginByUid($data['u']);
-		$info['skill'] = $this->skillModel->getUserSkill($info['i']);
-		
-		return json($info);
-	}
-	
-	public function getskill(){
-		$data = decode($this->request->post());
-		
-		$info = $this->skillModel->getSkillByInfo($data['i']);
-		return json($info);
-	}
-	
-	public function addskill(){
-		$data = decode($this->request->post());
-		
-		$info = $this->skillModel->addUserSkill($data['u'], $data['s']);
-		return json($info);
-	}
-	
+<?php
+namespace app\home\controller;
+
+use think\Controller;
+use app\user\model\UserSkill;
+
+class User extends Controller {
+	
+	private $userModel, $skillModel;
+	
+	public function _initialize(){
+		$this->skillModel = new UserSkill();
+	}
+	
+	public function login()
+	{
+		$data = decode($this->request->post());
+		$this->userModel = new \app\user\model\User(); 
+		
+		$info = $this->userModel->loginByUid($data['u']);
+		$info['skill'] = $this->skillModel->getUserSkill($info['i']);
+		
+		return json($info);
+	}
+	
+	public function getskill(){
+		$data = decode($this->request->post());
+		
+		$info = $this->skillModel->getSkillByInfo($data['i']);
+		return json($info);
+	}
+	
+	public function addskill(){
+		$data = decode($this->request->post());
+		
+		$info = $this->skillModel->addUserSkill($data['u'], $data['s']);
+		return json($info);
+	}
+	
+	public function load(){
+		$data = decode($this->request->post());
+		$id = $data['i'];
+		$path = "load/$id.txt";
+		
+		$file = fopen($path, "r") or die(json(['error'=>1009]));
+		$info = fread($file, filesize($path));
+		fclose($file);
+		
+		return json(['l'=>$info]);
+	}
+	
+	public function save(){
+		$data = decode($this->request->post());
+		$id = $data['i'];
+		$path = "load/$id.txt";
+		
+		$file = fopen($path, 'w') or die(json(['error'=>1009]));
+		fwrite($file, $data['l']);
+		fclose($file);
+		
+		return json(['error'=>0]);
+	}
+	
 }

+ 1 - 0
load/temp.txt

@@ -0,0 +1 @@
+