Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8
This is the forum to discuss the Wrox book Professional CodeIgniter by Thomas Myer; ISBN: 9780470282458
Welcome to the p2p.wrox.com Forums.

You are currently viewing the BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Display Modes
  #1 (permalink)  
Old November 5th, 2009, 12:07 PM
Authorized User
 
Join Date: Nov 2009
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
Default Shouldn't they be in a controller?

models/morders have the following codes.

And I am wondering, since there are nothing to do with a database, they can be in a controller.

Shouldn't they?

Code:
class MOrders extends Model{
 function  __construct(){
    parent::Model();
 }

function updateCart($productid,$fullproduct){
	//pull in existing cart first!
	$cart = isset($_SESSION['cart']) ? $_SESSION['cart'] : array();
	// $cart = $_SESSION['cart'];//$this->session->userdata('cart');
	$productid = id_clean($productid);
	$totalprice = 0;
	if (count($fullproduct)){
		if (isset($cart[$productid])){
			$prevct = $cart[$productid]['count'];
			$prevname = $cart[$productid]['name'];
			$prevprice = $cart[$productid]['price'];
			$cart[$productid] = array(
					'name' => $prevname,
					'price' => $prevprice,
					'count' => $prevct + 1
					);
		}else{
			$cart[$productid] = array(
					'name' => $fullproduct['name'],
					'price' => $this->format_currency($fullproduct['price']),
					'count' => 1
					);			
		}
	
		foreach ($cart as $id => $product){
			$totalprice += $product['price'] * $product['count'];
		}		
		
		$_SESSION['totalprice'] = $this->format_currency($totalprice);
		//$this->session->set_userdata('totalprice', $totalprice);
		$_SESSION['cart'] = $cart;
		//$this->session->set_userdata('cart',true);
		$this->session->set_flashdata('conf_msg', "We've added this product to your cart."); 
	}

}

function removeLineItem($id){
	$id = id_clean($id);
	$totalprice = 0;
	$cart = $_SESSION['cart'];//$this->session->userdata('cart');
	if (isset($cart[$id])){
		unset($cart[$id]);
		foreach ($cart as $id => $product){
			$totalprice += $product['price'] * $product['count'];
		}		
		$_SESSION['totalprice'] = $this->format_currency($totalprice);
		$_SESSION['cart'] = $cart;
		//$this->session->set_userdata('totalprice', $totalprice);
		//$this->session->set_userdata('cart',true);
		echo "Product removed.";
	}else{
		echo "Product not in cart!";
	}
}

function updateCartAjax($idlist){
	$cart = $_SESSION['cart'];//$this->session->userdata('cart');
	//split idlist on comma first
	$records = explode(',',$idlist);
	$updated = 0;
	$totalprice = $_SESSION['totalprice'];
	//$this->session->userdata('totalprice');
	if (count($records)){
		foreach ($records as $record){
			if (strlen($record)){
				//split each record on colon
				$fields = explode(":",$record);
				$id = id_clean($fields[0]);
				$ct = $fields[1];
				
				if ($ct > 0 && $ct != $cart[$id]['count']){
					$cart[$id]['count'] = $ct;
					$updated++;
				}elseif ($ct == 0){
					unset($cart[$id]);
					$updated++;
				}
			
			}
			
		}
		
		
		if ($updated){
			$totalprice=0;
			foreach ($cart as $id => $product){
				$totalprice += $product['price'] * $product['count'];
			}		

			$_SESSION['totalprice'] = $this->format_currency($totalprice);
			$_SESSION['cart'] = $cart;
			//$this->session->set_userdata('totalprice', $totalprice);		
			//$this->session->set_userdata('cart',true);
			
		
			switch ($updated){
				case 0:
				$string = "No records";
				break;
				
				case 1:
				$string = "$updated record";
				break;
				
				default:
				$string = "$updated records";
				break;
			}
			echo "$string updated";
			//$this->session->set_flashdata('update_count', $string ." updated");
		}else{
			echo "No changes detected";
			//$this->session->set_flashdata('update_count', "No changes detected");
		}
	}else{
		echo "Nothing to update";
		//$this->session->set_flashdata('update_count', "Nothing to update");
	}
}
Reply With Quote
  #2 (permalink)  
Old November 6th, 2009, 08:51 AM
Wrox Author
 
Join Date: May 2008
Location: Austin, TX, USA.
Posts: 53
Thanks: 0
Thanked 5 Times in 5 Posts
Default this is totally up to you

some folks, like myself, like to do all my data processing in the model. others prefer to do it in the controller. others put stuff like this in libraries or plugins or helpers.....
__________________
Thomas Myer
Author, Professional CodeIgniter
http://www.tripledogs.com
Reply With Quote
  #3 (permalink)  
Old November 6th, 2009, 04:24 PM
Authorized User
 
Join Date: Nov 2009
Posts: 26
Thanks: 3
Thanked 0 Times in 0 Posts
Default Ok, I got your point.

Thanks. I got your point.
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Controller Question susca BOOK: Professional CodeIgniter ISBN: 978-0-470-28245-8 1 July 6th, 2009 06:09 PM
PHP Controller cyber_kaley20 Beginning PHP 0 July 8th, 2007 10:12 PM
controller to controller tigransh Spring 1 November 10th, 2006 11:48 PM
throwaway controller mmasters BOOK: Professional Java Development with the Spring Framework 0 June 27th, 2006 10:56 AM
Model View Controller gpartin33324 Java GUI 0 October 4th, 2004 04:00 PM



All times are GMT -4. The time now is 06:22 PM.


Powered by vBulletin®
Copyright ©2000 - 2017, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.