codeigniter

Codeigniter active record with several like or?

ε祈祈猫儿з 提交于 2020-02-28 08:11:29
问题 Hey.. I've run into a problem using several "like" in my sql-query (generated with Codeigniter's activerecord): SELECT * FROM (`posts`) WHERE `city` LIKE '%test%' AND `title` LIKE '%%' OR `text` LIKE '%%' Thing is, it appears to read this query as if there was a parenthesis around the first like and the second like, but I want there to be a parenthesis around the second and the last like (I want it to compare if the last or the next to last works). How can I achieve this using Codeigniter's

Codeigniter active record with several like or?

≡放荡痞女 提交于 2020-02-28 08:10:10
问题 Hey.. I've run into a problem using several "like" in my sql-query (generated with Codeigniter's activerecord): SELECT * FROM (`posts`) WHERE `city` LIKE '%test%' AND `title` LIKE '%%' OR `text` LIKE '%%' Thing is, it appears to read this query as if there was a parenthesis around the first like and the second like, but I want there to be a parenthesis around the second and the last like (I want it to compare if the last or the next to last works). How can I achieve this using Codeigniter's

按对象字段对对象数组进行排序

陌路散爱 提交于 2020-02-28 01:38:00
如何按对象的字段之一(例如 name 或 count 对这个对象数组进行排序? Array ( [0] => stdClass Object ( [ID] => 1 [name] => Mary Jane [count] => 420 ) [1] => stdClass Object ( [ID] => 2 [name] => Johnny [count] => 234 ) [2] => stdClass Object ( [ID] => 3 [name] => Kathy [count] => 4354 ) .... #1楼 这是使用闭包的更好方法 usort($your_data, function($a, $b) { return strcmp($a->name, $b->name); }); 请注意,这不在PHP文档中,但是如果您使用5.3+闭包,则可以在其中提供可调用参数。 #2楼 如果您使用的是php oop,则可能需要更改为: public static function cmp($a, $b) { return strcmp($a->name, $b->name); } //in this case FUNCTION_NAME would be cmp usort($your_data, array('YOUR_CLASS_NAME','FUNCTION_NAME'

CI文件上传

妖精的绣舞 提交于 2020-02-27 22:52:22
1. 创建上传表单 使用文本编辑器新建一个文件 upload_form.php ,放入如下代码,并保存到 application/views/ 目录下: <html> <head> <title>Upload Form</title> </head> <body> <?php echo $error;?> <?php echo form_open_multipart('upload/do_upload');?> <input type="file" name="userfile" size="20" /> <br /><br /> <input type="submit" value="upload" /> </form> </body> </html> 你会注意到我们使用了表单辅助函数来创建 form 的起始标签,文件上传需要使用 multipart 表单, 辅助函数可以帮你正确生成它。还要注意的是,代码里有一个 $error 变量,当发生错误时, 可以用它来显示错误信息。 2. 上传成功页面 使用文本编辑器新建一个文件 upload_success.php ,放入如下代码,并保存到 application/views/ 目录下: < html > < head > < title > Upload Form </ title > </ head > < body > < h3

Retrieve second table as subarray in codeigniter query

不打扰是莪最后的温柔 提交于 2020-02-27 12:28:13
问题 I have two tables A & B, and B has a many:1 relationship with A. When querying rows from A I'd also like to have corresponding B records returned as an array and added to the result array from A, so I end up with something like this: A-ROW field field B-ITEMS item1 item2 item3 Is there a clean way to do this with one query (perhaps a join?), or should I just perform a second query of B on the id from A and add that to the result array? 回答1: It would be more efficient to join table B on table

[codeigniter4]系列开篇

偶尔善良 提交于 2020-02-27 09:22:27
最新中文手册 https://codeigniter-chinese.github.io/codeigniter4-user-guide/index.html CodeIgniter4与以往版本有大的变更 下载 CodeIgniter4 Git 是一个分布式版本控制系统。 CodeIgniter 可以在 GitHub 上公开访问。请注意,尽管我们在保持代码的基础功能上做出了大量的努力,但是我们并不能为开发分支的代码中的功能作担保。 稳定版可以从 GitHub Releases 获取。 开发版可以从 开发分支 获取。 安装 CodeIgniter4 可以手动安装,或使用 Composer 安装。 注解 在使用 CodeIgniter 之前, 请确认你的服务器符合 要求 . 手动安装 CodeIgniter 通过手动下载并解压压缩包来安装。 Composer 安装 虽然不是必须的,但你可以通过 composer create-project 命令来安装 CodeIgniter。 composer create-project codeigniter4/framework 运行 将 CodeIgniter 的文件夹和文件上传到你的服务器上。 index.php 文件将会在你项目根目录的 public 文件夹里。 使用文本编辑器打开 application/Config/App.php

How to use bootstrap in mPDF?

僤鯓⒐⒋嵵緔 提交于 2020-02-27 09:18:21
问题 I am currently using mpdf to generate my pdfs from html. So far with my current html that I am passing in, I am able to generate a one page pdf with a header and footer. However, if there is more than one page, my footer goes all the way to the bottom of the second page. Is there a way to add a header and footer for each page? I have tried $pdf->setHTMLHeader but it doesn't seem to take my css files in and it leaves an x where my logo is supposed to be. How can I do this? I have tried

CI 搜索 $this->db->where()

好久不见. 提交于 2020-02-27 08:42:49
该方法提供了4种方式让你编写查询语句中的 WHERE 子句: 注解( 所有的数据将会自动转义,生成安全的查询语句。 ) 1. 简单的 key/value 方式: $this -> db -> where ( 'name' , $name ); // Produces: WHERE name = 'Joe' 注意自动为你加上了等号。 如果你多次调用该方法,那么多个 WHERE 条件将会使用 AND 连接起来: $this -> db -> where ( 'name' , $name ); $this -> db -> where ( 'title' , $title ); $this -> db -> where ( 'status' , $status ); // WHERE name = 'Joe' AND title = 'boss' AND status = 'active' 2. 自定义 key/value 方式: 为了控制比较,你可以在第一个参数中包含一个比较运算符: $this -> db -> where ( 'name !=' , $name ); $this -> db -> where ( 'id <' , $id ); // Produces: WHERE name != 'Joe' AND id < 45 3. 关联数组方式: $array = array

去掉codeigniter地址中的index.php

折月煮酒 提交于 2020-02-27 02:57:53
+ 转载自: 去掉codeigniter地址中的index.php 版本:CodeIgniter_2.0.1 希望CI 应用的URL不包含index.php 例如: http://www.example.com/index.php/product/712 希望变成这样http://www.example.com/product/712 这样url更漂亮,也许这样seo更友好,通过urlrewrite就可以实现 只需用下面3个步骤就可以搞定: 1.建立.htaccess写入重写规则如下 [code] <IfModule mod_rewrite.c> RewriteEngine On RewriteBase / #Removes access to the system folder by users. #Additionally this will allow you to create a System.php controller, #previously this would not have been possible. #'system' can be replaced if you have renamed your system folder. RewriteCond %{REQUEST_URI} ^system.* RewriteRule ^(.*)$ /index

PHP CI(CodeIgniter) 如何去掉url中的index.php

此生再无相见时 提交于 2020-02-26 11:14:34
1、打开Apache配置文件httpd.conf,找到 1 #LoadModule rewrite_module modules/mod_rewrite.so 去掉前面的# 搜索AllowOverride,将相应Directory下的AllowOverride设置为All 1 AllowOverride All 2、在CI的根目录下,建立.htaccess文件,文件内容如下 1 RewriteEngine On 2 3 RewriteCond %{REQUEST_URI} ^system.* 4 RewriteRule ^(.*)$ /index.php?/$1 [L] 5 6 RewriteCond %{REQUEST_URI} ^application.* 7 RewriteRule ^(.*)$ /index.php?/$1 [L] 8 9 RewriteCond %{REQUEST_FILENAME} !-f 10 RewriteCond %{REQUEST_FILENAME} !-d 11 RewriteRule ^(.*)$ index.php?/$1 [L] 3、打开文件application/config/config.php,$config['index_page'] = "index.php";改为$config['index_page'] = ""; 1