codeigniter

Access array variable in session (CodeIgniter)

吃可爱长大的小学妹 提交于 2020-01-22 12:02:26
问题 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-

Codeigniter LIKE with wildcard(%)

爷,独闯天下 提交于 2020-01-22 06:44:47
问题 I have simple database query in codeigniter, however I cannot get search to work with wildcard. This is my code: $this->db->like('film.title',"%$query%"); $this->db->escape_like_str($query); $res = $this->db->get('film'); If I remove wildcard(%) then search works fine. Also $query is just string with user input. Any help is appreciated. 回答1: $this->db->like() automatically adds the %s and escapes the string. So all you need is $this->db->like('title', $query); $res = $this->db->get('film');

Hybrid Auth with Codeigniter

自古美人都是妖i 提交于 2020-01-22 04:55:09
问题 I downloaded the codeigniter extension of HybridAuth here: https://github.com/andacata/HybridIgniter I followed instructions on its use. When I try to login via any provider at: www.mydomainname.com/hauth/login/twitter it loads a page saying: HybridAuth Open Source Social Sign On PHP Library. hybridauth.sourceforge.net/ It never works. I have valid API credentials for Twitter and Facebook but both load this page and nothing else happens. Any tips would be greatly appreciated. UPDATE My log

Save data from dynamically created rows to database

怎甘沉沦 提交于 2020-01-22 03:43:47
问题 I am using Codeigniter. I have created a table that contains different columns. I wanted to create rows dynamically when clicking on the '+' button. Now i am able to create rows using jquery. I want to save the data to database. how can i save the values of each rows to database when i click on the '+' button? 回答1: You can use ajax request on this. First when you click + button, instead of just text in each column, you can put input fields. <tr> <td><input id="field1" type="text" /></td> <td>

Call php function in javascript without waiting for response

心不动则不痛 提交于 2020-01-22 03:38:24
问题 I know how to use $.ajax. I have a Codeigniter project so I just call: url:'<?php echo base_url()."somecontroller/somefunction"?>', This is all ok but ajax waits for the response. I just want to the call the url as you would by typing it in your browser. I don't want to wait for the response because the controller does a redirect and then loads a view. Also i need to be able to send some data via POST. How can I do this? 回答1: You can use the following for sending asynchronous request with

Codeigniter contact form email

橙三吉。 提交于 2020-01-22 02:19:06
问题 I'm trying to set up a contact form in Codeigniter (I'm running on xampp using Apache and I have a virtual host set up). I have the actual form working but when I try to link it up so that it emails the results I get an error. I've looked around and tried a few different solutions but I can't figure out what it is that I'm doing wrong. Controller: public function contact() { $this->load->helper('form'); $this->load->library('form_validation'); $this->form_validation->set_rules('name', 'your

Codeigniter | OVH | htaccess / url rewriting | Site very slow

落花浮王杯 提交于 2020-01-22 02:10:10
问题 Here is my htaccess for removing the index.php with codeigniter : RewriteEngine On RewriteCond $1 !^(index\.php|assets|robots\.txt) RewriteRule ^(.*)$ index.php/$1 [L] But with this .htaccess, there is an error "File not found." So, I'm searching, and here is a little solution : http://forum.ovh.com/showthread.php?93572-Codeigniter-et-htaccess Adding a "?" resolve the problem, but the site is sometimes very very slow, and sometimes very fast ! And sometimes, my style sheets don't load (assets

Codeigniter showing error: No database selected

我只是一个虾纸丫 提交于 2020-01-22 00:20:57
问题 I am using Codeigniter's DBForge class to create a database and table within that database. Here is code: if ($this->dbforge->create_database('new_db')) { $fields = array( 'blog_id' => array( 'type' => 'INT', 'constraint' => 5, 'unsigned' => TRUE, 'auto_increment' => TRUE ), 'blog_title' => array( 'type' => 'VARCHAR', 'constraint' => '100', ), 'blog_author' => array( 'type' => 'VARCHAR', 'constraint' => '100', 'default' => 'King of Town', ), 'blog_description' => array( 'type' => 'TEXT',

015.CI4框架CodeIgniter数据库操作之:带参数查询数

我与影子孤独终老i 提交于 2020-01-21 23:51:49
01.我们在Models中写数据库的操作。具体的查询代码如下: <?php namespace App\Models\System; use CodeIgniter\Model; class User_model extends Model { var $Db; function __construct() { parent::__construct(); //创建数据库连接 $this->Db = \Config\Database::connect(); } function getdata() { //带参数条件查询 $sql = "SELECT * FROM tp_user WHERE ( ID = ? AND ( MARK = ?))"; $sqlrst = $this->Db->query($sql, array('143', '2019091500000143')); $rst = $sqlrst->getRow(); return $rst; } } 02. 在控制器调用的代码如下: <?php namespace App\Controllers; class Home extends BaseController { // http://127.0.0.1/CI4/public/index.php/home/showdata var $User_Models;

CodeIgniter Check the connection to multi databases take long time

♀尐吖头ヾ 提交于 2020-01-21 20:25:13
问题 I try to connect to multi MySQL database in CI if the connection to the first DB fails, I try to connect to the second, I use this code from CI forum: http://ellislab.com/forums/viewthread/224522/#1030449 $db_obj = $this->database->load('xxx',TRUE); $connected = $db_obj->initialize(); if (!$connected) { $db_obj = $this->database->load('yyy',TRUE); } it works fine on local host, it tries to connect to 1st DB and fails, then directly connect to the 2nd DB (without any long time -- transparency)