<?php /** * CodeIgniter 的测试 Model * * CodeIgniter 输出 sql 语句代码是: * $this->db->last_query() */ class TestModel extends CI_Model { private $table = 'DBTable'; public function index() { $year = $this->input->post('year'); $month = $this->input->post('month'); $day = $this->input->post('day'); $this->load->database(); $result = $this->db ->select('*') ->from($this->table) ->where('year', $year) ->where('month', $month) ->where('day', $day) ->order_by('sort', 'DESC') ->get() ->rerult(); // 检查 sql 语句代码 $this->sqlout(__LINE__); return $result; } /* 功能:文件输出 sql 语句代码,用于测试 * * 调用方式:在查询构造器下方输入如下代码 * $this->sqlout(); * * 生成的文件目录:applicationmodels * 文件名:ClassName_line_sql.txt */ public function sqlout($line) { $testSql = $this->db->last_query(); if(isset($testSql)){ $sql = json_decode(str_replace(' ', ' ', json_encode($testSql))); file_put_contents(__DIR__.'/'.__CLASS__.'_'.$line.'_sql.txt', $sql); } } }
codeIgniter 跳转:redirect(‘signIn/index’);
php 换行符:PHP_EOL