codeigniter

call a helper function in controller in codeigniter

喜夏-厌秋 提交于 2020-01-01 19:21:31
问题 I created a helper for visit hits and it contains a function which inserts some data in to the database: hits_counter_helper.php : function count_hits($options = array()) { //Determine whether the user agent browsing your site is a web browser, a mobile device, or a robot. if ($this->agent->is_browser()) { $agent = $this->agent->browser() . ' ' . $this->agent->version() . ' - ' . $this->agent->platform(); } elseif ($this->agent->is_robot()) { $agent = $this->agent->robot(); } elseif ($this-

Codeigniter routing issues

拟墨画扇 提交于 2020-01-01 19:19:29
问题 I am customizing my routes in codeigniter, here is a sample of my routes.php: $route['default_controller'] = 'maincontroller/main'; $route['404_override'] = ''; $route['test'] = 'maincontroller/test'; here is the maincontroller class: class Maincontroller extends CI_Controller { public function __construct( ) { parent::__construct( ); $this->load->library('session'); $this->init( ); } public function main( ) { echo "in main"; } public function test( ) { echo "test"; } } but when i access this

Regenerate CRSF token codeigniter on submit Ajax

点点圈 提交于 2020-01-01 18:43:10
问题 Hi I am looking for the process of regeneration of csrf token in codeigniter when ever a form is submitted using ajax. I want the token to be regenerated without page refresh. Is there any way to do that. 回答1: There are two solutions I use at different times depending on the situation. 1. Slightly messy way but recommended Get the token name and hash value in your controller and set it somewhere on your page as a data field (wherever you choose). For instance // get the data and pass it to

codeigniter session working on local host but not working on server and also sit

隐身守侯 提交于 2020-01-01 14:53:10
问题 Hi Friends I am struggling session in codeigniter everything working fine my system but server or sit machine not working session public function voting() { //like and dislike controller $deal_id = $this->input->post('voteId'); $upOrDown = $this->input->post('upOrDown'); $session_id = $this->input->post('session_id'); $voted_id = $this->session->userdata('voted'); $voted_deal =$this->session->userdata('voted_deal'); if ($voted_id == $session_id && $voted_deal == $deal_id) { //defult session

How to set default function in codeIgniter when I visit Class with non-existent route?

淺唱寂寞╮ 提交于 2020-01-01 14:49:32
问题 The controller like this: class Abc extends CI_controller{ public function index(){...} public function f1(){...} } If url is http://host/app/Abc/index it get function index If url is http://host/app/Abc/f1 it get function f1 If url is http://host/app/Abc it get function index because it is default But if url is http://host/app/Abc/f2 it print 404 not found I expected that if url is http://host/app/Abc/f2 it can turn to index function. If can't do this,I want to add new function automatically

How to reload dataTable after deleting records/data?

和自甴很熟 提交于 2020-01-01 12:14:10
问题 I have generated records and each row has delete button, And when I click delete button it will delete the records from the db. Also, after delete it will reload dataTable. Any Help for this? DataTables: var table = $('#table').DataTable({ "processing": true, //some settings? }); jQuery: $(document).on('click', '[id^="delete-product-"]', function() { var id = this.id.split('-').pop(); $.ajax({ type: 'post', url: 'my_controller/delete_product', dataType: 'json', data: {id: id}, success:

$this->db->insert_id() not working in mysql codeigniter

我只是一个虾纸丫 提交于 2020-01-01 12:02:50
问题 I am just trying to get the latest auto generated key from the mysql table from codeiginitor. But it is not working some how. I have tried this code $this->db->insert_id() as well as $this->db->mysql_insert_id() I am getting the following error Severity: Notice Message: Undefined property: CI_DB_mysql_driver::$insert_id is the insert_id function not supported for mysql? How can we make it work? 回答1: CodeIgniter's insert_id() will only return an ID of an insert() . Unless you are executing

SEO-friendly URLs in CodeIgniter without the use of slugs?

六眼飞鱼酱① 提交于 2020-01-01 11:55:13
问题 Is there a way (via routing) in CodeIgniter to change: example.com/category/4 to example.com/category/foo-bar where Foo Bar is the name of category 4 in the database? Access from the SEO-friendly URL should be allowed, but access via the integer should cause a 404 error. This should also work dynamically, where any integer is automatically converted to a URL-safe version of its corresponding category name. I've seen a few solutions that use 'slugs'... is there a decent alternative? Thanks.

Codeigniter 3.0.0 - error 404 page not found

五迷三道 提交于 2020-01-01 11:42:13
问题 This is my first php framework. I have a php file in my controller which is posts.php but when I tried to run it localhost/codeigniter/index.php/posts, it displays error 404 .htaccess inside application folder <IfModule authz_core_module> Require all denied </IfModule> <IfModule !authz_core_module> Deny from all </IfModule> autoload.php $autoload['libraries'] = array('database'); $autoload['helper'] = array('url'); config.php $config['base_url'] = 'http://localhost/codeigniter/'; $config[

connecting postgresql and codeigniter

强颜欢笑 提交于 2020-01-01 11:39:13
问题 I'm new using postgresql and I've been using Codeigniter for a year. I have a small postgresql database and I wanna call it from Codeigniter. In my database.php file I have this setup: $active_group = 'default'; $query_builder = TRUE; $db['default'] = array( 'dsn' => 'pgsql:host=localhost;port=5432;dbname=test;user=postgres;password=aPass', // 'dsn' => '', 'hostname' => 'localhost', 'username' => 'postgres', 'password' => 'aPass', 'database' => 'test', 'dbdriver' => '', 'dbprefix' => '',