Created
December 23, 2011 01:12
-
-
Save SET001/1512629 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
class Controller_Article extends Layout{ | |
public $secure_actions = array( | |
'delete' => array('moderator'), | |
'save' => array('moderator')); | |
public function action_save(){ | |
$id = $this->request->param('id'); | |
$article = ORM::factory('article', $id); | |
if (!$article->loaded()){ | |
$article = new Model_Article(); | |
$article->added = date('Y-m-d H:i:s'); | |
$article->user_id = $this->user->id; | |
} | |
if (!empty($_POST)){ | |
$article->name = arr::get($_POST, 'name'); | |
$article->text = arr::get($_POST, 'text'); | |
try{ | |
$article->save(); | |
$image = Upload::save($_FILES['cover'], $article->id . '.jpg', 'images/articles'); | |
$this->request->redirect('article/index'); | |
} | |
catch(Exception $e){ | |
$errors = $e->getMessage(); | |
print_r($errors); | |
die; | |
} | |
} | |
$this->template->content = View::factory('article_save') | |
->set('article', $article) | |
->render(); | |
} | |
public function action_view($id){ | |
$article = new Model_Article($id); | |
if (!$article->loaded()) die('wrong ig'); | |
$this->template->content = View::factory('article_view')->set('article', $article); | |
} | |
public function action_delete($id){ | |
$article = new Model_Article($id); | |
if (!$article->loaded()) die('wrong ig'); | |
$article->delete(); | |
$this->request->redirect('article'); | |
} | |
public function action_index(){ | |
$query = ORM::factory('article'); | |
if ($q = arr::get($_GET, 'q')){ | |
$query->where('name', 'like', '%'.strip_tags($q).'%'); | |
} | |
$articles = $query->find_all(); | |
$this->template->content = View::factory('insider_2col') | |
->set('sidebar', View::factory('article_sidebar')) | |
->set('main', View::factory('article_index') | |
->set('articles', $articles)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment