参考
- 目次 : CodeIgniter ユーザガイド 日本語版
- モデル | 基礎編 CodeIgniter Guide 徹底ガイド!
- kenjis/php-framework-benchmark: PHP Framework Benchmark
インストール
git clone https://github.com/tukiyo/docker-php5.6-apache
cd docker-php5.6-apache
sh files/get_codeigniter2.sh
chmod -R 777 app/tmp
docker-compose up
model
- application/config/database.php の修正は終わっていること。
-
select id,name FROM shop
を行いたい。
touch application/models/shop.php
application/controllers/Welcome.php
<?php
if (!defined('BASEPATH')) exit('No direct script access allowed');
class Welcome extends CI_Controller {
public function index() {
$this->load->model('Shop');
$res = $this->Shop->get_info();
echo "<pre>";
var_dump($res);
//$this->load->view('welcome_message');
}
}
application/models/Shop.php
<?php
class Shop extends CI_Model {
public function __construct() {
$this->load->database();
}
public function get_info() {
$this->db->select('id,name');
$this->db->from('shop');
$query = $this->db->get();
//echo $this->db->last_query();
$res = null;
if ($query->num_rows() > 0) {
$res = $query->result();
}
return $res;
}
}