facebook twitter hatena line email

Php/codeigniter/model

提供: 初心者エンジニアの簡易メモ
移動: 案内検索

application/models/Hello_model.php

<?php
class Hello_model extends CI_Model {

    function __construct() {
        parent::__construct();
    }

    function get_data() {
        $data = [
            'title' => 'hello!',
            'message' => 'Helloworld!!'
        ];
        return $data;
    }
}

application/controller/Hello.php

<?php
defined('BASEPATH') OR exit('No direct script access allowed');

class Hello extends CI_Controller {
    public function index()
    {
        $this->load->model('Hello_model');
        $data = $this->Hello_model->get_data();
        $this->load->view('hello', $data);
    }
}

参考:https://qiita.com/atwata/items/2de3433c55014111daa9