<?php

namespace app\controllers;

use app\models\Photo;

class PhotosController extends \lithium\action\Controller {

	public function index() {
		$photos = Photo::all();
		return compact('photos');
	}

	public function view() {
		$photo = Photo::first($this->request->id);
		return compact('photo');
	}

	public function add() {
		$photo = Photo::create();

		if (($this->request->data) && $photo->save($this->request->data)) {
			$this->redirect(array('Photos::view', 'id' => $photo->id));
		}
		return compact('photo');
	}

	public function edit() {
		$photo = Photo::find($this->request->id);

		if (!$photo) {
			$this->redirect('Photos::index');
		}
		if (($this->request->data) && $photo->save($this->request->data)) {
			$this->redirect(array('Photos::view', 'args' => array($photo->id)));
		}
		return compact('photo');
	}
}

?>