Post by harryusa » Mon Feb 28, 2011 12:46 am

I have designed a few customized templates and I probably put more PHP in them than I should have but pages are reading directories and processing fine so far. I am now interested in some insight and guidance on how the controller script for a corresponding template handles _GET and _POST data and then how it effects the output of the template. Tell me if I am barking up the wrong tree:
_GET and _POST data are routed by /index.php to the appropriate controller script after being put into the $this array.
The controller script processes the data, keeping it in the $this array and calls the template file which then outputs the user?
Someone the used the term "magically appearing variables"; I guess since the controller and the template are essentially contiguous from the server's processing standpoint, the variables don't need to be supergobal or global.

How much of my understanding is wrong? Any tips on designing the module for _GET and _POST data?
My next task will be to interface with the database.
Thanks,
Harry
_
Last edited by harryusa on Mon Feb 28, 2011 11:20 pm, edited 2 times in total.

New member

Posts

Joined
Mon Feb 21, 2011 12:23 pm

Post by JAY6390 » Mon Feb 28, 2011 12:57 am

Hi Harry

$this is not an array as such, it's an object, and it references the current object that calls it. $this->request->get is an array, as is $this->request->post, and are the $_GET and $_POST arrays after they have been cleaned up
What exactly are you needing to access the database or $_GET/POST values in the template for exactly. That is a big no no. Templates are meant to only have basic logic relating to the view only, not interacting with data (that's the Model's function in the MVC architecture) or directly accessing $_GET and $_POST values (that should be handled by the Controller)

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by harryusa » Mon Feb 28, 2011 3:04 am

Jay6390,
A brief overview of the issue. Aside from the product sales aspect of OC, I need to have a way to calculate the price of a service by dimension, square inch, volume or height and width, on a file that is uploaded by a customer. I would do the price calculation for a service and add it to the database and cart array upon the customer's submission of their specification. The file upload and file browsing templates I wrote are already done and working in OC, now I need a way to take the values the customer enters and process them into a custom price and item specification. I am not going to go overboard with writing the entire specification and options to the OC database as I already have a database and algorithm for that. I will simply add a product which will be for the discrete use only by the logged in customer and then deleted by a cron operation after the customer is logged out or the product quantity is 0. Anyway that is the problem in a nutshell. Not terribly difficult, except for someone new to OOP and MVC.
I look forward to your further input.
-Harry

New member

Posts

Joined
Mon Feb 21, 2011 12:23 pm

Post by JAY6390 » Mon Feb 28, 2011 3:30 am

I see. From what I read in your first post I got the impression that this was for a theme you were going to resell, not a custom cart you're making for yourself. Personally I would use an ajax request if you are wanting to communicate to get rates etc, or if you know the formula and only need to load values upon page load, pass the variables using $this->data array in the controller upon page load, and set it for use with your JavaScript

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by harryusa » Mon Feb 28, 2011 9:25 pm

OK let me get this straight, so let's say the user's input generates this server request:

http://www.thewebsite.com/index.php?rou ... =5&width=6

_GET['height'] and _GET[''width'] are routed by the index.php to the order.php in the service folder of the controller.
Do I have this right so far?

I can then write a function/method to handle the calculation and output it through a variable or object from the CLASS. I need to study the syntax of passing the data to and from the CLASS module, that is where I am in the dark. Also upon the customer wishing to add the service to their cart, I need to update the PRODUCT table with this "unique" product and append the CART array. I could either write my own SQL script into the CLASS or try to figure out how to find and use the ADMIN SQL that updates the PRODUCT table.

How does that sound? And any clues or resources you could point me toward in properly writing a CLASS?
I was looking over this tutorial:
http://www.killerphp.com/tutorials/obje ... page-1.php

New member

Posts

Joined
Mon Feb 21, 2011 12:23 pm

Post by JAY6390 » Mon Feb 28, 2011 9:32 pm

The values are already in the class (the Controller) for you, you can access them using
$this->request->get['width']
and
$this->request->get['height']
never use $_GET and $_POST directly, this could cause problems with magic quotes
Then you can use a calculation to determine the value you want to pass to the view. Using
$this->data['var_name_here'] = 'calculated value to replace this';
Then in the template you just need to use $var_name_here to use the value

As for the adding a unique product to the product table and appending to the cart, that will require a bit of work, and I'm not actually sure why you would need that to be honest

Image


User avatar
Guru Member

Posts

Joined
Wed May 26, 2010 11:47 pm
Location - United Kingdom

Post by harryusa » Mon Feb 28, 2011 11:09 pm

JAY6390,
You've given me a good starting point.
I think it will take a little practice to more firmly grasp the context of OOP model, but I can already appreciate its flexibility and versatility as opposed to in-line coding.
As for the adding a unique product to the product table and appending to the cart, that will require a bit of work, and I'm not actually sure why you would need that to be honest
Maybe there is a better way of doing this, but from what I understand, you can't just assign a random price to a product, it has to be derived from a base price and any other options selected by the user. If I have a customized price, unique to that user's job I thought I would have to give them a PRODUCT to purchase that reflects the price that was calculated.
What would be another way of doing this?
-Harry

New member

Posts

Joined
Mon Feb 21, 2011 12:23 pm
Who is online

Users browsing this forum: No registered users and 68 guests