codeigniter

Limit SQL join when using CodeIgniter active record class

不羁的心 提交于 2020-01-24 08:02:07
问题 I'm getting a product listing. Each product may have 1 or more image, I only want to return the first image. $this->db->select('p.product_id, p.product_name i.img_name, i.img_ext'); $this->db->join('products_images i', 'i.product_id = p.product_id', 'left'); $query = $this->db->get('products p'); Is there anyway to limit the db->join to 1 record using the CI active record class? 回答1: Add $this->db->limit(1); before calling $this->db->get('products p'); . See the docs at ellislab.com: search

How to pass multiple parameters to a library in CodeIgniter?

假装没事ソ 提交于 2020-01-24 03:26:08
问题 I am making a library for CodeIgniter, and I wish to pass multiple parameters of different types (a PDO object, username and password, configurations, etc). I know I can pass an array of all of these things, but that doesn't seem to be the best way of doing things (as $params can't ever describe what is needed). How can I pass multiple parameters to a library? Thanks in advance. 回答1: There are several approaches to this particular problem. I'll list (in preferred order) ways I know to solve

Codeigniter - Bootstrap Modal - passing data

坚强是说给别人听的谎言 提交于 2020-01-23 07:10:10
问题 I am pretty new to Codeigniter and aiming to follow best practice as I learn. Currently I have a table that is generated via DB HTML Table <tr> <td> <a class="galName" href="#myModal" data-toggle="modal" > <?php echo $gal['name']; ?> </a> </td> <td> <?php echo $gal['clientName']; ?> </td> </tr> <?php endforeach; ?> The Modal <div class="modal fade hide modal-creator" id="myModal" style="display: none;" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data

Codeigniter - Bootstrap Modal - passing data

末鹿安然 提交于 2020-01-23 07:09:05
问题 I am pretty new to Codeigniter and aiming to follow best practice as I learn. Currently I have a table that is generated via DB HTML Table <tr> <td> <a class="galName" href="#myModal" data-toggle="modal" > <?php echo $gal['name']; ?> </a> </td> <td> <?php echo $gal['clientName']; ?> </td> </tr> <?php endforeach; ?> The Modal <div class="modal fade hide modal-creator" id="myModal" style="display: none;" aria-hidden="true"> <div class="modal-header"> <button type="button" class="close" data

Problems with CodeIgniter (and allowed_types)

北战南征 提交于 2020-01-23 04:23:15
问题 Morning guys. I'm trying to use Plupload along with CodeIgniter. I tried uploadify before Plupload and it worked awesome, the main problem with uploadify is that it never sent the CSRF code, no matter what I used, this was really odd so I reviewed Plupload and I made it work as expected in matter of minutes. However, it ONLY works well with the HTML5 uploader and not with the Flash Uploader. Reviewing the logs I found the reason why it was not working: while using the CodeIgniter File

Conflict between Codeigniter AUtoload and Flourish Autoload functions

余生长醉 提交于 2020-01-23 03:37:05
问题 I am developing a web application, using the Codeigniter ( http://codeigniter.com/ ) framework plus the Flourish library ( unframework ) ( http://flourishlib.com/ ). I simply dropped the flourish folder into my application, then I created a flourish initialization and config files as instructed (these create the Flourish autoload). This is my folder structure: ---auxcode\ --------init.php --------config.php --------flourish\ ---system\ ---application\ ---public_html\ The init file ONLY

CodeIgniter框架--目录结构

爷,独闯天下 提交于 2020-01-23 01:02:11
•MVC的组成部分 模型 (Model) 代表你的数据结构。通常来说,你的模型类将包含取出、插入、更新你的数据库资料这些功能。 视图 (View) 是展示给用户的信息。一个视图通常是一个网页,但是在 CodeIgniter 中,一个视图也可以是一个页面片段,如页头、页尾。它还可以是一个 RSS 页面,或任何其它类型的“页面”。 控制器 (Controller) 是模型、视图以及其他任何处理 HTTP 请求所必须的资源之间的中介,并生成网页。 目录结构 : application :项目目录 cache :存放数据或模板缓存文件 config :配置文件目录 controllers :MVC的控制器,继承CI_Controller core:项目的核心程序 errors :错误提示模板 helpers:项目的辅助函数 hooks:钩子,在不修改系统核心文件的基础上扩展系统功能 language:语言包 libraries:通用类库 logs:日志 models:MVC的模型,一般继承CI_Model third_party:第三方库 views:MVC的视图,主要是模板 system :框架程序目录 core :核心程序:框架的基类、初始化 database :数据库操作相关的程序 fonts:字库 helpers:辅助函数 language:语言包 libraries:通用类库

019.CI4框架CodeIgniter辅助函数类之:Array数组查询

♀尐吖头ヾ 提交于 2020-01-22 16:23:03
01. 数组辅助函数,可以方便的查看数组内部的成员,用法如下图所示: <?php namespace App\Controllers; class Hello extends BaseController { //http://127.0.0.1/CI4/public/ //http://127.0.0.1/CI4/public/index.php/hello //http://127.0.0.1/CI4/public/index.php/hello/hello protected $helpers = ['array', 'App\Helpers\Tx']; function __construct() { } public function hello() { $data = [ '班级' => [ '一班' => [ '姓名' => '张三' ], '二班' => [ '姓名' => '李四' ] ] ]; $rst = dot_array_search('*.*.姓名', $data); ShowMessage($rst); } public function index() { echo '青青子衿悠悠我心'; } //-------------------------------------------------------------------- } 02

How to send variable data when redirecting to previous page

孤街浪徒 提交于 2020-01-22 12:31:46
问题 I am using the following codes to redirect my user to previous page after a particular task is done. if (isset($_SERVER['HTTP_REFERER'])) { $this->session->set_userdata('previous_page', $_SERVER['HTTP_REFERER']); } else { $this->session->set_userdata('previous_page', base_url()); } The above code I use in a controller and the following code in another controller.. .... some other stuffs... I am updating database values here.... $this->db->where('t_expenseid', $t_expenseid); query=$this->db-

Access array variable in session (CodeIgniter)

☆樱花仙子☆ 提交于 2020-01-22 12:03:32
问题 I have an array called config. I'm trying to echo a variable from the array in the session. I've tried: echo $this->session->userdata('config['item']'); but it doesn't work. What's wrong with my syntax here? I've print_r'd my session and the items are in the config array. I've also tried: echo $this->session->userdata("config['item']"); I get no errors this time, but no data either. 回答1: If config is an array . And item is string name of what you want to get from config then echo $this-