Преглед на файлове

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; 
-		
 	}