CAFPE Docs
  • Class

Classes

  • Article_model
  • Articles
  • Auth
  • Auth_controller
  • Bcrypt
  • Hierarchical_controllers
  • Ion_auth
  • Ion_auth_model
  • MY_Controller
  • MY_Lang
  • MY_Model
  • Pages
  • Private_pages
  • Public_controller
  • Seeder
  • Slug
  • User_sessions
  • Users

Functions

  • action_result
  • actions_widget
  • admin_area_buttons
  • base64_current_url_encode
  • base64_url_decode
  • base64_url_encode
  • current_lang
  • jscript_tag
  • lang_switcher
  • logged_in
  • redirect_lang
  • site_url_lang
  • style_tag
 1  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 
<?php defined('BASEPATH') or exit('No direct script access allowed');

class Articles extends Auth_controller
{
    public function __construct()
    {
        parent ::__construct();
        $this->load->model('article_model');
    }

    /**
     * Maps to:
     *    - site_url + articles
     *    - site_url + articles/index
     */
    public function index()
    {
        $this->data['articles'] = [];
        $articles = $this->article_model->order_by('date', 'DESC')->get_all();
        if($articles) {
            $this->data['articles'] = $articles;
        }
    }

    /**
     * Maps to:
     *    - site_url + articles/view/$id
     */
    public function view($id = null)
    {
        $article = $this->article_model->get($id);
        if (! $article) {
            show_404();
        }

        $this->data = array_merge($this->data, $article);
    }

    /**
     * Maps to:
     *    - site_url + articles/create
     */
    public function create()
    {
        $this->load->helper('form');
        // insert data
        $id = $this->article_model->from_form()->insert();
        if ($id) {
            $this->status('ok', true);
            redirect_lang('admin/articles/view/'.$id);
        }
        // not valid posted data
        elseif($this->input->method() === 'post') {
            $this->status('error');
        }
    }

    /**
     * Maps to:
     *    - site_url + articles/edit/$id
     */
    public function edit($id = null)
    {
        $this->load->helper('form');
        $this->data['_'] = $this->article_model->get($id);
        if (! $this->data['_'] || ! $id) {
            show_404();
        }
        // update data if provided
        if($this->input->method() === 'post') {
            if ($this->article_model->from_form(null, null, array('id' => $id))->update()) {
                $this->status('ok', true);
                redirect_lang('admin/articles/view/'.$id);
            }
            // not valid posted data
            else {
                $this->status('error');
            }
        }
    }

    /**
     * Maps to:
     *    - site_url + articles/delete/$id
     */
    public function delete($id = null)
    {
        if ($this->article_model->delete($id)) {
            $this->status('ok', true);
        } else {
            $this->status('error', true);
        }
        redirect_lang('admin/articles');
    }
}
CAFPE Docs API documentation generated by ApiGen