Problem in adding more products to cart using Codeigniter Sessions.? | 2my4edge

19 May 2015

Problem in adding more products to cart using Codeigniter Sessions.?

I have recently worked on codeigniter project with cart, there i got an issue with adding more products to the cart. i have used one thing for that cart to add more product using session. that is simple thing only let me tell you that solution you just follow that and use it for you project. i have used Codeigniter 2.2.2. now 3.0.0 is the latest codeigniter version. i'll tell you the solution for two versions.  

facing problem in php cart codeigniter

CodeIgniter Version 2.2.2

Here is the solution, actually the cart is running with Sessions so in the controller we have to load the session.

$this->load->library('session');

Like the above code we have to load the session in controller constructors. the browser will take max 4kb of cookie size if those exceed, it wont take for that we are using session database,

CONFIG FILE
Change that in config file,
       Application -> config -> config.php
in the config file

$config[‘sess_use_database’] = FALSE
to

$config[‘sess_use_database’] = TRUE

Then we have to add more database table

CREATE TABLE IF NOT EXISTS  `ci_sessions` (
    session_id varchar(40) DEFAULT '0' NOT NULL,
    ip_address varchar(45) DEFAULT '0' NOT NULL,
    user_agent varchar(120) NOT NULL,
    last_activity int(10) unsigned DEFAULT 0 NOT NULL,
    user_data text NOT NULL,
    PRIMARY KEY (session_id),
    KEY `last_activity_idx` (`last_activity`)
);

CodeIgniter Version 3.0.0
Here also same like version 2.2.2 to but here some updates are there so we don't want to change that in config page.

The ‘database’ driver uses a relational database such as MySQL or PostgreSQL to store sessions. This is a popular choice among many users, because it allows the developer easy access to the session data within an application - it is just another table in your database.

However, there are some conditions that must be met:
  • Only your default database connection (or the one that you access as $this->db from your controllers) can be used.
  • You must have the Query Builder enabled.
  • You can NOT use a persistent connection.
  • You can NOT use a connection with the cache_on setting enabled.
In order to use the ‘database’ session driver, you must also create this table that we already mentioned and then set it as your $config['sess_save_path'] value. For example, if you would like to use ‘ci_sessions’ as your table name, you would do this:

$config['sess_driver'] = 'database';
$config['sess_save_path'] = 'ci_sessions';

FOR MYSQL
CREATE TABLE IF NOT EXISTS `ci_sessions` (
        `id` varchar(40) NOT NULL,
        `ip_address` varchar(45) NOT NULL,
        `timestamp` int(10) unsigned DEFAULT 0 NOT NULL,
        `data` blob NOT NULL,
        PRIMARY KEY (id),
        KEY `ci_sessions_timestamp` (`timestamp`)
);

FOR PostgreSQL
CREATE TABLE "ci_sessions" (
        "id" varchar(40) NOT NULL,
        "ip_address" varchar(45) NOT NULL,
        "timestamp" bigint DEFAULT 0 NOT NULL,
        "data" text DEFAULT '' NOT NULL,
        PRIMARY KEY ("id")
);

CREATE INDEX "ci_sessions_timestamp" ON "ci_sessions" ("timestamp");


FOR MORE REFERENCE




1 comment:

  1. This particular papers fabulous, and My spouse and i enjoy each of the perform that you have placed into this. I’m sure that you will be making a really useful place. I has been additionally pleased. Good perform! ABestPro

    ReplyDelete

^