Re: passing $_POST variables to classes




"Jerry Stuckle" <jstucklex@xxxxxxxxxxxxx> schreef in bericht
news:euadnVHarKOSCTPbnZ2dnUVZ_q2hnZ2d@xxxxxxxxxxxxxx
amygdala wrote:
Hi all,

I'm starting this new project in which I'ld like to implement sort of a
design pattern I have seen being used in the CodeIgniter framework.

Basically, the site will examine the URI and based on the segments of the
URI it will fire up some controller class, for instance, say I have an
inbox in which end-users can view messages they got from other users,
they'ld start at:

http://www.somesite.com/inbox/view/

This will then call upon the function view in the class inbox:

class Inbox extends Controller
{
// ...
public function view()
{
// ...
}
// ...
}

Any trailing segments of the URI will be passed as supplement arguments
to the function.

Now, if $_POST variables are sent to some page and are needed by the
called upon function in the appropriate class, would it be bad practice
to simply extract those $_POST variables from the superglobal $_POST
inside this function? Preferably I would like to send the $_POST
variables as arguments to the function, but I'm not sure how to implement
this correctly, nor am I even completely sure as to why this would be
better practice, other than that the function will only accept predefined
arguments.

What are your views on implementing such a 'pattern' (if you will). Would
you even suggest such an implementation, or am I bound to get into
trouble with proposed pattern?

Thank you in advance.

It's better to pass parameters. It makes your class reusable.

What happens, for instance, if later you decide to store the data in the
$_SESSION variable? Or you need to change the name of the $_POST
variable, i.e. due to a conflict? Your existing code would be pretty
worthless.

Ah yes, of course, good points. Why didn't I think of that. :)

A compromise would be to have a function which only extracts the data, but
I don't like that.

Sorry, I'm a bit dense today, I can't seem to grasp the simplest of concepts
today, would you care to eleborate on this? Where would this function reside
for instance, and what would it do exactly. Before answering, please view my
comments beneath also, it might save you unnecessary typing. :-)

And you can send the variables - just like you do anything else, i.e.

func($_POST['var'1]);


What I am a bit worried about though (and I know this could be a bit
unlikely), is that when users accidentally (or on purpose), submit a larger
URI (with more segments), my functions will misinterpret the trailing URI
segments, when in fact it should be using $_POST vars.

How would I ensure, giving the fact that trailing URI segments will be
passed to functions as supplement arguments, they will be interpreted as URI
segments and not $_POST data? Any ideas? Thanks!

Or should I perhaps give up on the 'flexible' trailing URI segment stuff and
write some preprocessing code (is this perhaps what you where referring to
when you mentioned a function extracting data?) that will eveluate whether
the URI is acceptable for that particular class? This would somehow seem to
destroy the whole concept I think.


--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@xxxxxxxxxxxxx
==================


.



Relevant Pages

  • Re: passing $_POST variables to classes
    ... I'm starting this new project in which I'ld like to implement sort of a design pattern I have seen being used in the CodeIgniter framework. ... Basically, the site will examine the URI and based on the segments of the URI it will fire up some controller class, for instance, say I have an inbox in which end-users can view messages they got from other users, they'ld start at: ... Now, if $_POST variables are sent to some page and are needed by the called upon function in the appropriate class, would it be bad practice to simply extract those $_POST variables from the superglobal $_POST inside this function? ... What I am a bit worried about though, is that when users accidentally, submit a larger URI, my functions will misinterpret the trailing URI segments, when in fact it should be using $_POST vars. ...
    (comp.lang.php)
  • Re: regular expression for matching url?
    ... > an HTTP url. ... > is from the uri tcllib package: ... > Is there a more complete pattern available? ...
    (comp.lang.tcl)
  • Re: To add a column such that the column will be the first column
    ... Thanks Uri and Joe. ... Since another table has the column name plant as the ... first column I was trying to make the second table follow the pattern. ...
    (microsoft.public.sqlserver.programming)
  • passing $_POST variables to classes
    ... URI it will fire up some controller class, for instance, say I have an inbox ... This will then call upon the function view in the class inbox: ... if $_POST variables are sent to some page and are needed by the called ... What are your views on implementing such a 'pattern'. ...
    (comp.lang.php)