codeigniter

How to use MySQLi Driver in Codeigniter

假如想象 提交于 2020-01-10 02:50:11
问题 Hi I'm kinda new to this and I would like to ask someone here that are experts in codeigniter framework and PHP. How can I use mysqli drivers in php native query? For example. My code: Model class Home_model extends CI_Model{ public function getusers(){ $q = "SELECT * FROM `users`"; return $r = mysqli_query($q); } } Controller: class Home extends CI_Controller{ public function iterateuser(){ while($row = mysqli_fetch_object($this->Home_model->getusers())){ echo $row->username; } } My code

Codeigniter - SEO Friendly URL Structure (Slug Implementation)

本秂侑毒 提交于 2020-01-10 02:03:11
问题 I want's to develop a website in codeigniter framework in which i can access any webpage via slug. For example just like WordPress and Magento we can access category page by www.sitename.com/category_type/category_detailpage and also we can access that Category_detail directly just by adding its slug after main URI www.sitename.com/category_detailpage. So my question is that how i have to design schema of slug table in database if you have any case study Project Code for this Slug Directory

Check codeigniter query errors instead of showing them to the user

☆樱花仙子☆ 提交于 2020-01-09 09:50:10
问题 How can I check if a query went wrong instead of showing errors to users (containing database info which is unsafe). Let's say I have such situation where my paging class takes a URI segment to show page example.com/page/uri_segment . If someone write it like this example.com/page/bla_bla_bla I get an error that shows information about my database. How can I handle this? 回答1: In application/config/database.php set // suppress error output to the screen $db['default']['db_debug'] = FALSE; In

how to get ip address in codeigniter?

江枫思渺然 提交于 2020-01-09 09:20:09
问题 I am doing this following code for login attempt & i want get IP address of my local machine.. if ( !$this->session->userdata('login_attempts') ) { $this->session->set_userdata('login_attempts', 0); } $attempts = ($this->session->userdata('login_attempts') + 1); $this->session->set_userdata('login_attempts', $attempts); // Check if the session. if ( $this->session->userdata('login_attempts') > 4 ) { echo 'hi....login attempt is over'; } // Failed. So, update the session echo $ip = $_SERVER[

Do form validation with jquery ajax in codeigniter

做~自己de王妃 提交于 2020-01-09 05:31:31
问题 How can i do form validation in codeigniter if i don't want to refresh the page? Basically i do this: $config = array( array( 'field' => 'c_name', 'label' => 'Name', 'rules' => 'trim|required' ), array( 'field' => 'c_job', 'label' => 'Job', 'rules' => 'trim|required', ) ); $this->form_validation->set_rules($config); if($this->form_validation->run() == true) { $this->load->model('model'); //..... } else{ $this->load->view('view'); } But if i send data with ajax and the page doesn't refresh,

Accessing Class Properties with Spaces

二次信任 提交于 2020-01-09 02:14:29
问题 stdClass Object ([Sector] => Manufacturing [Date Found] => 2010-05-03 08:15:19) So I can access [Sector] by using $object->Sector but how can I access [Date Found] ? 回答1: You can do it this way: $object->{'Date Found'} 回答2: have you tried $property = 'Date Found'; $object->{$property}; Or simply $object->{'Date Found'}; 回答3: try $var="Date Found"; $this->$var But I doubt that much you can have spaces in class properties names in php 回答4: Replace the spaces with underscores in the property

How to call codeigniter controller function from view

吃可爱长大的小学妹 提交于 2020-01-08 16:56:42
问题 How to call codeigniter controller function from view? When i call the function in a controller, get a 404 page. 回答1: Codeigniter is an MVC (Model - View - Controller) framework. It's really not a good idea to call a function from the view. The view should be used just for presentation, and all your logic should be happening before you get to the view in the controllers and models. A good start for clarifying the best practice is to follow this tutorial: https://codeigniter.com/user_guide

Codeigniter整合Ucenter同步登陆

馋奶兔 提交于 2020-01-07 13:42:21
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> Ucenter整合Discuz同步登陆 1、先安装UCenter 再安装Discuz 2、登录Discuz,用户名:admin, 密码:admin 3、登录Discuz后台管理 密码:admin 4、登录UCenter ,选择应用。会有一个已通信成功的UCenter+Discuz应用 或:在安装Discuz之后,会有一个UCenter,并且已建立好一个应用,可以用这个,日前未试过同步登录是否可行。 Codeigniter整合Ucenter同步登陆 说明:本地测试服务器配置开启URL重写 1、在康盛网站 http://www.comsenz.com/downloads/install/ucenter 下载ucenter源码包 2、解压后,将uc_client文件夹复制到CI根目录。同样,在advanced/examples复制api文件夹、include文件夹、config.inc.php到CI根目录。 3、在UCENTER管理中心添加一个应用, 应用类型:其他 应用名称:CI、 应用的主URL:【要建立连接的网站网址】如:http:// www.what.com 、 应用IP:127.0.0.1 通信密钥:到config.inc.php找‘UC_KEY’字段的值。 选择“开启同步、接受通知”。 得到应用id

How to set base url in codeigniter

岁酱吖の 提交于 2020-01-07 12:30:10
问题 I have codeigniter project and I want to upload in local server : 192.168.x.xxx . But I don't know how to change base_url in config file from localhost to local server contain IP address. How to set $config['base_url'] ? Thanks 回答1: I would set it some thing like $config['base_url'] = 'http://localhost/project/'; With domain $config['base_url'] = 'http://www.yourdomainname.com/'; End base url with / If you don't set the base url links and css, images etc will not work properly. 回答2: try it

CodeIgniter重定向页面问题

谁都会走 提交于 2020-01-07 10:35:47
【推荐】2019 Java 开发者跳槽指南.pdf(吐血整理) >>> redirect ( $uri = '' , $method = 'auto' , $code = NULL ) 参数: $uri ( string ) -- URI string //url字符串路径 $method ( string ) -- Redirect method ('auto', 'location' or 'refresh') //指定重定向方式 $code ( string ) -- HTTP Response code (usually 302 or 303) // 通过 HTTP 头重定向到指定 URL 。你可以指定一个完整的 URL ,也可以指定一个 URL 段, 该函数会根据配置文件自动生成改 URL 。 第二个参数用于指定一种重定向方法。可用的方法有: auto 、 location 和 refresh 。 location 方法速度快,但是在 ISS 服务器上不可靠。默认值为 auto ,它会根据你的服务器环境 智能的选择使用哪种方法。 第三个参数可选,允许你发送一个指定的 HTTP 状态码,这个可以用来为搜索引擎创建 301 重定向。 默认的状态码为 302 ,该参数只适用于 location 重定向方法,对于 refresh 方法无效 redirect('/article