Codeigniter: Logic in Nested Views
I have a template.php that includes a header, footer and main content.
However, in my template.php, I would like to add a shopping cart widget that utilises the shopping cart class, the form class and obviously the session class.
I want the widget to intially be a form before the cart which gathers simple data from the user (name, email, some dropdown boxes and checkbox information) and sends these pa开发者_StackOverflow社区rameters to a session (stored in the database using CI_SESSIONS) which will be used by the application (related products) (show products based on checkbox selections) and the cart.
I want the logic to process through the widget without having to reload the entire page (AJAX/JS?) and then use the session to store the cart data as the user browses through the application.
Can anyone recommend any reading materials or libraries to put me in the right direction to an answer?
Regards,
From what I understand in your problem, I think you can implement your shopping cart widget as a partial view. I usually structure my template.php
to be very bare except for some stuff that need to 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 you can call functions that you need in your view partial.
Use codeigntier HMVC to create view partials. Then you can have a separate module for the widget where you can handle forms, sessions etc.
You can also use Ajax to refresh the specific module (loaded in a div) so that all pages of your website spread across multiple tabs have the same view.
精彩评论