Пример #1
0
 public function action_delete($id = null)
 {
     if ($category = Model_Category::find($id) and \Security::check_token()) {
         $category->delete();
         Session::set_flash('success', e('Deleted category #' . $id));
     } else {
         if (!\Security::check_token()) {
             Session::set_flash('error', e('Could not delete category #' . $id . ', CSRF token not valid!'));
         } else {
             Session::set_flash('error', e('Could not delete category #' . $id));
         }
     }
     Response::redirect('blog/admin/category');
 }
Пример #2
0
 public function action_index()
 {
     // Pagination configuration
     $config = array('per_page' => 3, 'uri_segment' => 'page');
     // Get the category_slug route parameter
     $category_slug = $this->param('category_slug');
     if (is_null($category_slug)) {
         $config['total_items'] = Model_Post::count();
     } else {
         $config['total_items'] = Model_Post::count(array('where' => array('category_id' => Model_Category::find('first', array('where' => array(array('slug' => $category_slug))))->id)));
     }
     // Create a pagination instance named 'posts'
     $pagination = \Pagination::forge('posts', $config);
     $data['posts'] = Model_Post::query()->related(array('author', 'category'))->rows_offset($pagination->offset)->rows_limit($pagination->per_page);
     if (!is_null($category_slug)) {
         $data['posts']->where('category_id', Model_Category::find('first', array('where' => array(array('slug' => $category_slug))))->id);
     }
     $data['posts'] = $data['posts']->get();
     $this->template->title = "Posts";
     $this->template->content = View::forge('post/index', $data);
     $this->template->content->set('pagination', $pagination, false);
 }