php CI3 App模型
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php CI3 App模型相关的知识,希望对你有一定的参考价值。
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class App_model extends CI_Model {
public function __construct()
{
parent::__construct();
}
public function query($string, $execute = false)
{
/* Query */
$query = $this->db->query($string);
if(!$execute){
$query = $query->result();
/* Return */
if($query){
return $query;
}else{
return false;
}
}
}
public function listing($table, $options = false)
{
/* Limit */
if(@$options['limit']){
if(is_array($options['limit'])){
$this->db->limit($options['limit'][0], $options['limit'][1]);
}else{
$this->db->limit($options['limit']);
}
}
/* Order By */
if(@$options['order']){
foreach ($options['order'] as $key => $value) {
$this->db->order_by($key, $value);
}
}
/* Like */
if(@$options['like']){
$like = 0;
$this->db->group_start();
foreach ($options['like'] as $key => $value) {
if($like == 0){
$this->db->like($key, $value);
}else{
$this->db->or_like($key, $value);
}
$like++;
}
$this->db->group_end();
}
/* Where */
if(@$options['where']){
$this->db->group_start();
foreach ($options['where'] as $key => $value) {
$this->db->where($key, $value);
}
$this->db->group_end();
}
/* Join */
if(@$options['join']){
foreach ($options['join'] as $value) {
$this->db->join($value[0], $value[1], $value[2]);
}
}
/* Select */
if(@$options['select']){
foreach ($options['select'] as $column) {
$this->db->select($column);
}
}
/* Get */
$query = $this->db->get($table);
$query = $query->result();
/* Return */
if($query){
return $query;
}else{
return false;
}
}
public function count($table, $options = false)
{
/* Where */
if(@$options['where']){
foreach ($options['where'] as $key => $value) {
$this->db->where($key, $value);
}
}
/* Like */
if(@$options['like']){
$like = 0;
foreach ($options['like'] as $key => $value) {
if($like == 0){
$this->db->like($key, $value);
}else{
$this->db->or_like($key, $value);
}
$like++;
}
}
/* Join */
if(@$options['join']){
foreach ($options['join'] as $value) {
$this->db->join($value[0], $value[1], $value[2]);
}
}
/* Return */
return $this->db->count_all_results($table);
}
public function get($table, $options = false)
{
/* Limit */
$this->db->limit(1);
/* Order By */
if(@$options['order']){
foreach ($options['order'] as $key => $value) {
$this->db->order_by($key, $value);
}
}
/* Where */
if(@$options['where']){
foreach ($options['where'] as $key => $value) {
$this->db->where($key, $value);
}
}
/* Join */
if(@$options['join']){
foreach ($options['join'] as $value) {
$this->db->join($value[0], $value[1], $value[2]);
}
}
/* Select */
if(@$options['select']){
foreach ($options['select'] as $column) {
$this->db->select($column);
}
}
/* Get */
$query = $this->db->get($table);
$query = $query->result();
/* Return */
if($query){
return $query[0];
}else{
return false;
}
}
public function insert($table, $data)
{
/* Insert */
$this->db->insert($table, $data);
/* Return */
return $this->db->insert_id();
}
public function update($table, $where, $data)
{
/* Where */
if($where){
foreach ($where as $key => $value) {
$this->db->where($key, $value);
}
}
/* Update */
$this->db->update($table, $data);
}
public function delete($table, $where)
{
/* Where */
if($where){
foreach ($where as $key => $value) {
$this->db->where($key, $value);
}
}
/* Update */
$this->db->delete($table);
}
}
/* End of file App_model.php */
/* Location: ./application/models/App_model.php */
以上是关于php CI3 App模型的主要内容,如果未能解决你的问题,请参考以下文章
在使用 route53 在云端连接后,Amazon Ec2 上的 Ci3 会话数据出现问题。在公共 DNS 上启动时工作
php 将观察者注册到`app / Providers / AppServiceProvider.php`中的`boot()`方法中的模型