Quantcast
Channel: CodeIgniter Forums - All Forums
Viewing all 14176 articles
Browse latest View live

Can I run mysql query in constant.php file to make constant dynamic

$
0
0
question could be funky, can I run mysql query into application/config/constant.php file to make constant dynamic or any proper way to make constant dynamic based on value coming from db.

Log file styling lib

$
0
0
Hi all,

I'm seeking a library that provide the CI log files in a view that is styled nicely.

Eg ERROR levels log items are red, Debug is blue etc.

Anyone know of such a project kicking around?


Many thanks

What is the smtp server Codeigniter uses?

$
0
0
I don't have a smtp server on my machine, but Codeigniter allows me to send emails, how is that possible? Does Codeigniter comes with an smtp server?

How to using sweet alert in codeigniter

$
0
0
I want to make validation form login user when form validation error show error form controller to view codeigniter ? anyone can help me

Changing my hosts file is not working

$
0
0
I'm trying to redirect bing.com to google.com, so when I enter bing.com on my browser address I should be redirected to google.com instead but it's just not working...

I opened the hosts file using notepad as an administrator, and change it to

172.217.25.110 bing.com # should redirect to google but not!

I'm trying to learn something and this is a part of the tutorial that I'm reading on, this is just an excerpt that is somehow related to Codeigniter.

Json Handling in ViewCI

$
0
0
hey everyone .. I am a nwebiew to CI and a fresher too  neeed your help , 
I have a wordpress blog from where i have fetch posts through JSON and tat JSON data i want to view in CI VIEW 
i am sharing the code of controller 
Code:
<?php

class Code extends CI_Controller{

public function __construct()
{
    
    parent::__construct();
}    
    
    
    
public function test()
{      
        // echo "daewd"; die();
    //$otherdb = $this->load->database('blogs', TRUE); // the TRUE paramater tells CI that you'd like to return the database object.
      //$query = $otherdb->get('wp_users');
      //$data['wp_users']=$query->result_array();
      $data = file_get_contents('http://wordpress-34240-73651-202010.cloudwaysapps.com/wp-json/wp/v2/posts');
     $decode=json_decode($data, true);
      var_dump($decode);
       //print_r($decode['0']);  
      //echo implode(" ",$data);
      //print_r("<pre>");  
     // print_r($data['wp_posts']);      
    
    // $this->load->view('post',$data);
}    


    
}

so please tell me how i can show my posts and tiles of posts in the view

How to use Forge Class to create a database schema?

$
0
0
I'm using CodeIgniter 3.1.0 to develop an app. In order to improve installation, I've written an Install_Controller, and an Install_Model.
I want to use Database Forge class to manage the database schema, but it's not very clear in user guide and nothing on Google helps.
I need to use $this->dbforge->create_database, because the user knows nothing about database, so all he will do is MySQL "Next, next, install" and then run a Windows batch file that run PHP as web server, so from Chrome he can use URL to install the app.

User guide says: In order to initialize the Forge class, your database driver must already be running, since the forge class relies on it.

So I have setup the config/database.php with user, pwd, dbname and so on... Even because I need it to use in app. That's working fine in app.

After I delete my database to start over from a fresh install and try to load the Install URL, give me the error: Message: mysqli::real_connect(): (HY000/1049): Unknown database 'test'

So, how can I use Forge Class to create database schema, if I need to have it first?

Some code...

Code:
$db['default'] = array(
   'dsn' => '',
   'hostname' => 'localhost',
   'username' => 'root',
   'password' => 'root',
   'database' => 'test',
   'dbdriver' => 'mysqli'
);

$autoload['libraries'] = array('database');

class Install extends CI_Controller
{
   public function __construct()
   {
       parent::__construct();
   }

   public function index()
   {
       $this->load->model('install_model');
       $this->install_model->createDabase();
   }
}

class Install_model extends CI_Model {
   function __construct() {
       parent::__construct();
   }

   function createDabase() {
       $this->load->dbforge();

       if ($this->dbforge->create_database('test'))
           echo 'Database created!';
       else
           echo 'Database error!';
   }
}

I made a very dirty workaround, I hope someone give me a nice answer...
1. Remove database from autoloader.
2. Use multiple databases, the default one is the same, but I created a second one having empty database name.
3. Use the second database with Forge Class, instead of the default until create schema, then I back to the default to create tables.
4. Load manually the default database in others Controllers

Should I hash / encrypt user id for when set in session

$
0
0
I would like to know when I set user id in session when the user  logins in

If it is a good idea to encrypt user id  and then decrypt it in a model

Just for added security.

Forge Class bug in numeric field name

$
0
0
If you set a field name in table that is a numeric value, because array_merge in DB_forge.php function add_field, this numeric names are transformed into array index, making wrong result.

Code:
$fields = array(
                '0000' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '0100' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '0200' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '0300' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '0400' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '0500' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '0600' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '0700' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '0800' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '0900' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '1000' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '1100' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '1200' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '1300' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '1400' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '1500' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '1600' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '1700' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '1800' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '1900' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '2000' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '2100' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '2200' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
                '2300' => array(
                        'type' => 'BIT',
                        'constraint' => '1',
                        'null' => FALSE,
                        'default' => 0,
                ),
        );

        f( !$this->dbforge->add_field( $fields ) )
            return $this->db->error();


Return:

Error Code: 1064. You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '0000 BIT(1) NOT NULL DEFAULT 0,   0100 BIT(1) NOT NULL DEFAULT 0, 0200 BIT(1) NO'


Dump of SQL:

Code:
CREATE TABLE IF NOT EXISTS `schedule_time` (
0000 BIT(1) NOT NULL DEFAULT 0,
0100 BIT(1) NOT NULL DEFAULT 0,
0200 BIT(1) NOT NULL DEFAULT 0,
0300 BIT(1) NOT NULL DEFAULT 0,
0400 BIT(1) NOT NULL DEFAULT 0,
0500 BIT(1) NOT NULL DEFAULT 0,
0600 BIT(1) NOT NULL DEFAULT 0,
0700 BIT(1) NOT NULL DEFAULT 0,
0800 BIT(1) NOT NULL DEFAULT 0,
0900 BIT(1) NOT NULL DEFAULT 0,
0 BIT(1) NOT NULL DEFAULT 0,
`1` BIT(1) NOT NULL DEFAULT 0,
`2` BIT(1) NOT NULL DEFAULT 0,
`3` BIT(1) NOT NULL DEFAULT 0,
`4` BIT(1) NOT NULL DEFAULT 0,
`5` BIT(1) NOT NULL DEFAULT 0,
`6` BIT(1) NOT NULL DEFAULT 0,
`7` BIT(1) NOT NULL DEFAULT 0,
`8` BIT(1) NOT NULL DEFAULT 0,
`9` BIT(1) NOT NULL DEFAULT 0,
`10` BIT(1) NOT NULL DEFAULT 0,
`11` BIT(1) NOT NULL DEFAULT 0,
`12` BIT(1) NOT NULL DEFAULT 0,
`13` BIT(1) NOT NULL DEFAULT 0
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_general_ci 


Expected SQL:

Code:
CREATE TABLE `schedule_time` (
    `0000` BIT NOT NULL DEFAULT 0,
    `0100` BIT NOT NULL DEFAULT 0,
    `0200` BIT NOT NULL DEFAULT 0,
    `0300` BIT NOT NULL DEFAULT 0,
    `0400` BIT NOT NULL DEFAULT 0,
    `0500` BIT NOT NULL DEFAULT 0,
    `0600` BIT NOT NULL DEFAULT 0,
    `0700` BIT NOT NULL DEFAULT 0,
    `0800` BIT NOT NULL DEFAULT 0,
    `0900` BIT NOT NULL DEFAULT 0,
    `1000` BIT NOT NULL DEFAULT 0,
    `1100` BIT NOT NULL DEFAULT 0,
    `1200` BIT NOT NULL DEFAULT 0,
    `1300` BIT NOT NULL DEFAULT 0,
    `1400` BIT NOT NULL DEFAULT 0,
    `1500` BIT NOT NULL DEFAULT 0,
    `1600` BIT NOT NULL DEFAULT 0,
    `1700` BIT NOT NULL DEFAULT 0,
    `1800` BIT NOT NULL DEFAULT 0,
    `1900` BIT NOT NULL DEFAULT 0,
    `2000` BIT NOT NULL DEFAULT 0,
    `2100` BIT NOT NULL DEFAULT 0,
    `2200` BIT NOT NULL DEFAULT 0,
    `2300` BIT NOT NULL DEFAULT 0,
) DEFAULT CHARACTER SET = utf8 COLLATE = utf8_general_ci

[SOLVED] SQL update using OUTPUT clause

$
0
0
I'm trying to use the OUTPUT clause here https://msdn.microsoft.com/en-us/library/ms177564.aspx

What I'm doing is updating a column that contains a key for a record.  So say the key is 10.  I need to update it to 11 and return that 10.  This can be accomplished by using a simple update query but codeigniter isn't liking it and won't return any results even though it does complete.

This query does not return any results and I get an error trying to use result_array(), result(), or row()
Code:
UPDATE
  KEY_COUNTERS
SET
  KEYS_COUNTERS = KEYS_COUNTERS + 1
OUTPUT
  deleted.KEYS_COUNTERS
WHERE
  KEY_COUNTERS_ID = 'KEY'

This query runs as well and I can run result_array() and get the deleted key but I don't want to have to run a select and then update.
Code:
DECLARE @KEY INT;

SELECT
  @KEY = KEYS_COUNTERS+1
FROM
  KEY_COUNTERS
WHERE
  KEY_COUNTERS_ID = 'KEY'

UPDATE
  KEY_COUNTERS
SET
  KEYS_COUNTERS = @KEY
OUTPUT
  deleted.KEYS_COUNTERS
WHERE
  KEY_COUNTERS_ID = 'KEY'

Can anyone tell me why the first query doesn't return results but the bottom one does.  If I run this query in SQL management studio I get the same result so only codeigniter isn't working.  The only thing I can think is that since the first query only has the Update query that it doesn't return results because of codeigniter.

Creating multilanguage site

$
0
0
Hi!

I'm familiar with lang helper and lang library, but I was wondering if there is a better way to do this. I don't really like the fact, that my views are a bunch of html code containing nothing but variables.

Is there a solution where a view would contain actual text and the CI would recognize that text when loading the view and changed the text according to user language setting? I know I could create multiple versions of the same view (one for every language), but that would mean making changes to the same html code in multiple places, which is again a bad idea.

Thank you!

Form Validation Help

$
0
0
Sorry if this isn't the correct section to post. I took over the management of a site that uses codeigniter, and the previous account registration page gave the following format for errors when filling out the registration forms for its fields:

 
.jpg   currenterror.JPG (Size: 17.43 KB / Downloads: 20)

However, when I try to add more fields to the account registration page, adding new form validation rules as instructed in the codeigniter manual for each respected field in the controller for the page, the format for the errors is as following:


.jpg   desirederror.JPG (Size: 12.11 KB / Downloads: 19)
which appears above the fields at the top of the page.

I believe this is the expected error message format. I believe there is nothing in the controller that results in the original error messages, and I'd like to have all fields use the same (second) format since I know how to edit it/can control it. So I guess my question is whether there is some hidden location for form validation? I've looked in the imported form_validation library, all associated models/views that are relevant to the controller, and can't seem to find any where to delete the old error format.

If I need to provide more, specific information I can. Thanks for the help in advance.

How to migrate from CI3. X to CI4

$
0
0
Hi,

How to migrate from CI3. X to CI4


Thank you for your help

Regards

Adding Dynamic Data To Views

$
0
0
When I add my data the first $data array gets block by second data array

And I am unable to view the data in the first array

Any idea's whats causing it and how to solve it.


Code:
public function index($post_id) {
$post_data = $this->post_model->getpost($post_id);
        
$div_id = 1;

// First Array
$data = array(
   'title' => 'Welcome to CodeIgniter',
   'islogged' => $this->user_model->is_logged(),
   'username' => $this->user_model->getusername()
);

// Second Array
$data = array(
   'post_user_id' => $this->user_model->getuserid(),
   'post_title' => $post_data['subject'],
   'post_message' => $this->parsedown->text($post_data['message']),
   'post_id' => $post_data['post_id'],
   'post_div_id' => $div_id,
   'post_votes' => $post_data['votes']
);

$data['forum_id'] = $post_data['forum_id'];

$data['page'] = 'forum/post';

$this->load->view('default', $data);

}


Views > default.php


PHP Code:
<?php $this->load->view('template/common/header');?><?php $this->load->view('template/common/navbar');?>
<?php $this
->load->view('template/' $page);?>
<?php $this
->load->view('template/common/footer');?>

db->insert error

$
0
0
PHP Code:
        for($i 0$i 1000000;$i++){
            
$uid uniqid('rsv'true);

            
$this->db->set('uid',$uid);
            
$this->db->set('data','toto' $i);
            
$this->db->reset_query();
            if ( 
$this->db->insert('ddr') == false ){

                break;
            }
            
$this->db->reset_query();
        } 

Error message Fatal error: Allowed memory size of 134217728 bytes exhausted  in /system/database/DB_driver.php on line 703

Ion_auth remember me IE 11

$
0
0
I've come accross a very strange behaviour of IE 11 together with the fabulous Ion_auth library.
On my login pages (on 4 different websites) I have a "Remember me" checkbox. I leave it unchecked. On localhost, if I close the browser - IE 11 - without logging out, it forces me to login again at my next visit. That's how it should be.
On the live versions (hosted) however, IE 11 will log me in automatically, even when "Remember me" was unchecked.
I tried the same in Chrome. That browser doesn't remember me unwantedly.
Anyone who can explain this?

Crashkurs CodeIgniter! (deutsch)

$
0
0
Hallo zusammen, 

ich suche jemanden mit Erfahrung in CodeIgniter der mir die ersten Schritte erklären und beibringen kann. 
Das ganze stelle ich mir online, über Skype oder ähnlich, vor. Du erklärst mir anhand von praktischen Beispielen die Grundschritte von CodeIgniter und ich bezahle dich dafür. Ganz einfach!

Wer interesse und Zeit hat darf sich gerne hier bei mir per PN melden. Danke!

http://forum.codeigniter.ch/thread-5.html

Installed class via composer, need help using.

$
0
0
I installed https://github.com/phpWhois/phpWhois through composer and turned on the autoload feature, but I can't figure out usage based on the documentation.

It is installed in the app/vendor/phpwhois folder.

Can someone point me in the right direction?

Luthier - Updated (Alpha)

$
0
0
Hi folks  Smile

Recently I've started a personal project called Luthier. It's still an Alpha version, but now it's available with Composer so you can try it out

What is Luthier?

Luthier is a set of classes that extends the framework and helps with the development of large and complex applications. It's inspired by Laravel

Key features
  • Laravel-inspired static Route class
  • Route groups
  • Resource (RESTFul) controllers
  • Middleware support

I will appreciate all your comments and suggestions

GitHub:
https://github.com/ingeniasoftware/luthier

Planned Server Downtime Jan 21, 2017

$
0
0
Our forum and website (codeigniter.com) may be offline between 18:00 PST Sat Jan 21st and 08:00 PST Sun Jan 22nd (02:00-16:00 UTC Sunday Jan 22nd).

BCIT's data centre, where we are hosted, has scheduled maintenance during this period.

We have a CDN arrangement with Cloudflare, and they have a cached version of the website available, but the forum is not cached.
Viewing all 14176 articles
Browse latest View live


<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>