Problem in adding more products to cart using Code-igniter Sessions.?
Problem in adding more products to cart using Code-igniter Sessions.? Unable to add more items into Code-igniter Cart ? Issue with adding more products to the cart. we have used Code-igniter 2.2.2. now 3.0.0 is the latest code-igniter version. There is solution for two versions.
Code-igniter Version 2.2.2
Actually the cart is running with Sessions so in the controller we have to load the 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,
Change that in config file,
Application -> config -> config.php
in the config file
$config[‘sess_use_database’] = FALSE
$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`) );”
Code-igniter 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’;
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`) );
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");