Хочу добавить изображение в мои сообщения использую Codeigniter - PullRequest
0 голосов
/ 26 ноября 2018

Я пытаюсь добавить изображение к своему сообщению, проверил все и Google, но другой метод, который все еще не отвечал моим требованиям, это мой Post_model и Post Controller

    <?php
class Post_m extends MY_Model
{
    protected $_table_name = 'posts';
    protected $_order_by = 'pubdate desc, id desc';
    protected $_timestamps = TRUE;
    public $rules = array(
        'pubdate' => array(
            'field' => 'pubdate',
            'label' => 'Publication date',
            'rules' => 'trim|required|exact_length[10]'
        ),
        'title' => array(
            'field' => 'title',
            'label' => 'Title',
            'rules' => 'trim|required|max_length[100]'
        ),
        'category_id' => array(
            'category_id' => 'Category_id',
            'label' => 'Category ID',
            'rules' => 'trim|required'
        ),
        'slug' => array(
            'field' => 'slug',
            'label' => 'Slug',
            'rules' => 'trim|required|max_length[100]|url_title'
        ),
        'body' => array(
            'field' => 'body',
            'label' => 'Body',
            'rules' => 'trim|required'
        ),
        'post_image' => array(
            'field' => 'post_image',
            'label' => 'Upload Image',
            'rules' => 'trim'
        )
    );

    public function get_new ()
    {
        $post = new stdClass();
        $post->title = '';
        $post->slug = '';
        $post->body = '';
        $post->post_image = '';
        $post->pubdate = date('Y-m-d');
        return $post;
    }

    public function set_published(){
        $this->db->where('pubdate <=', date('Y-m-d'));
    }

    public function get_recent($limit = 3){

        // Fetch a limited number of recent articles
        $limit = (int) $limit;
        $this->set_published();
        $this->db->limit($limit);
        return parent::get();
    }

и мой Post Controller

<?php

/**
 *   Posts CONTROLLER
 * @property  post_m
 */
class Posts extends Admin_Controller
{


    public function __construct ()
    {
        parent::__construct();
        $this->load->model('post_m');
    }

    public function index ()
    {
        // Fetch all post

        $this->data['title'] = 'Posts | Gatinbox Admin';
        $this->data['site_name'] = 'Gatinbox Admin';
        $this->data['posts'] = $this->post_m->get();

        // Load view
        $this->data['subview'] = 'admin/post/index';
        $this->load->view('admin/layout', $this->data);
    }

    public function edit ($id = NULL)
    {
        // Fetch a post or set a new one
        if ($id) {
            $this->data['post'] = $this->post_m->get($id);
        }
        elseif ($this->data['errors']){
            echo 'post could not be found';
        }
        else {
            $this->data['post'] = $this->post_m->get_new();

        }

        // Set up the form
        $rules = $this->post_m->rules;
        $this->form_validation->set_rules($rules);

        // Process the form
        if ($this->form_validation->run() == TRUE) {
            $data = $this->post_m->array_from_post(array(
                'title',
                'category_id',
                'slug',
                'body',
                'pubdate',
                'post_image'
            ));

            $this->post_m->save($data, $id);
            redirect('admin/posts');
        }

        // Load the view
        $this->data['categories'] = $this->category_m->get_categories();
        $this->data['title'] = 'Edit | Gatinbox Admin';
        $this->data['site_name'] = 'Gatinbox Admin';
        $this->data['subview'] = 'admin/post/edit';
        $this->load->view('admin/layout', $this->data);
    }

    public function delete ($id)
    {
        $this->post_m->delete($id);
        redirect('admin/posts');
    }
}

Итак, мой вопрос: 1) как мне добавить конфигурацию загрузки 2) Будет ли загрузка выполняться в post_model или post controller 3) Пожалуйста, используйте мой код для ответа, я все еще новичок с codeigniter Спасибо заранее.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...