public static function show($id) { $chef = Chef::find($id); if ($chef) { $recipes = Recipe::find_by_chef_id($chef->id); $comments = Comment::find_by_chef_id($chef->id); $recipes_for_comments = array(); foreach ($comments as $comment) { $recipes_for_comments[$comment->recipe_id] = Recipe::find($comment->recipe_id); } View::make('chef/show.html', array('chef' => $chef, 'recipes' => $recipes, 'comments' => $comments, 'recipes_for_comments' => $recipes_for_comments)); } else { Redirect::to('/', array('error' => 'Käyttäjää ei löytynyt')); } }
public function destroy() { // Poista käyttäjän reseptit $chefs_recipes = Recipe::find_by_chef_id($this->id); foreach ($chefs_recipes as $recipe) { /* @var $recipe Recipe */ $recipe->destroy(); } // Poista käyttäjän kommentit $chefs_comments = Comment::find_by_chef_id($this->id); foreach ($chefs_comments as $comment) { /* @var $comment Comment */ $comment->delete(); } $query = DB::connection()->prepare("DELETE FROM Chef WHERE id = :id"); $query->execute(array('id' => $this->id)); }