Codeigniter: logic in nested views

I have a template.php that contains the header, footer and main content.

However, in my template.php, I would like to add a shopping cart widget that uses the shopping cart class, the form class, and obviously the session class.

I want the widget to be in the form of a form in front of the cart, which collects simple data from the user (name, email address, some pop-ups and a checkbox) and sends these parameters to the session (stored in the database using CI_SESSIONS), which will be used application (accompanying products) (show products based on flag selection) and cart.

I want the logic to be processed through the widget without reloading the entire page (AJAX / JS?), And then use a session to store the basket data when the user views the application.

Can anyone recommend any reading material or library to lead me in the right direction to answer?

Hello,

+4
source share
2 answers

From what I understand in your problem, I think you can implement the shopping cart widget as a partial view. I usually build my template.php to be very bare, except for some things that should be there. Here is an example
layout/template.php

 <html> <head> <?php $this->load->view('layout/head'); ?> </head> <body> <div class='header'> <?php $this->load->view('layout/body_header'); ?> </div> <div class='content'> <?php echo $content; ?> </div> <div class='widget'> <?php $this->load->view('cart/widget'); ?> </div> <div class='footer'> <?php $this->load->view('layout/body_footer'); ?> </div> </body> 

Then you can use ajax in your cart/widget.php so that you can call the functions you need in your partial view.

+4
source

Use codeigntier HMVC to create partial views. Then you can have a separate module for the widget, where you can handle forms, sessions, etc.

You can also use Ajax to update a specific module (loaded in a div) so that all pages of your website appear on multiple tabs of the same kind.

+1
source

All Articles