瀏覽代碼

Fixed issue when add page reloads due to error (anime wasn't being returned, so the view would say "Find an anime" and would not have anime data in the hidden fields)

Michael Francis 14 年之前
父節點
當前提交
1f30528f63
共有 1 個文件被更改,包括 43 次插入20 次删除
  1. 43 20
      controllers/AnimelistController.php

+ 43 - 20
controllers/AnimelistController.php

@@ -65,34 +65,57 @@ class AnimeListController extends \lithium\action\Controller {
 	//Ensure the correct user here 
 	public function add($id = null)
 	{
-		if (empty($this->request->data))
+		//If id is null,
+		if ('id' == null) {
+			//Redirect them to the search page
+			return $this->redirect('Animelist::addsearch');
+		}
+
+		//Find the requested anime
+		$anime = Anime::find('first', array('conditions' => array('special_id' => $id)));
+		$entry = null;
+
+
+		//If data was submitted
+		if ($this->request->data)
 		{
-			if ('id' != null) 
+			//Create an entry with the data
+			$entry = Entry::create($this->request->data);
+
+			//Get the current user
+			$user = Auth::check('default');
+			$username = $user['username'];
+
+			//Break the tags into an array
+			if (isset($this->request->data['tags']))
 			{
-				$anime = Anime::find('first', array('conditions' => array('special_id' => $id)));
-				$entry = null;
-				return compact('anime', 'entry');
+				$entry->my_tags = explode(',', $this->request->data['tags']);
+				unset($this->request->data['tags']);
+			}
+			
+			//If the entry is valid
+			if ($entry->validates()) {
+				//Store it, :TODO: make sure this passes at some point, silent failure sucks
+				$entry->add($username);
+
+				//Redirect the user to their anime list
+				return $this->redirect("/animelist/view/$username");	
 			}
-			return array('anime' => null, 'entry' => null);
 		}
-		$entry = Entry::create($this->request->data);
-		$user = Auth::check('default');
-		$username = $user['username'];
 
-		if (isset($this->request->data['tags']))
+		return compact('entry', 'anime'); 
+	}
+
+	public function edit($id = null)
+	{
+		if (id != null)
 		{
-				$entry->my_tags = explode(' ', $this->request->data['tags']);
-				unset($this->request->data['tags']);
+			//Get the ani
 		}
-		
-		if ($entry->validates()) {
-			$entry->add($username);
-
-			return $this->redirect("/animelist/view/$username");	
+		else 
+		{
+			//Error message
 		}
-
-		return $entry; 
-		
 	}