Re: passing $_POST variables to classes
- From: "amygdala" <noreply@xxxxxxxxxxx>
- Date: Tue, 31 Jul 2007 04:24:08 +0200
"Rik" <luiheidsgoeroe@xxxxxxxxxxx> schreef in bericht
news:op.twa29wl2qnv3q9@xxxxxxxxxxxx
On Tue, 31 Jul 2007 03:23:32 +0200, amygdala <noreply@xxxxxxxxxxx> 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?
There's nothing wrong with using $_POST directly. If however, you're
writing an app that might get it's instructions another way (for instance
the commandline, SOAP, instruction files), it might be handy to let a
controller decide what kind of request it gets, and create a request
object accordingly. When this is used in the code further one, it saves
you having to write the entire interfaces for these 'channels' again, and
assures that all requests are handled in the same manner. Offcourse, the
response for all these channels is usually different, then again 'what
kind of response do I want' i just part of the request offcourse. (Even
when just talking HTTP GETS/POST there might be a difference between calls
for entire HTML pages or for instance JSON objects).
Yes of course, this all makes sense too. And you're probably right, given
the type of requests you mentioned here, they would probably call for
different response types too. And indeed, this wouldn't necessarily mean
that the request interfaces (the arguments) need to be different.
But I have to agree with Jerry's comment (see Jerry's reply) here that if
for instance I decided to use $_SESSION of even $_GET vars for calling my
class functions it would break the interfaces. I did not think of that yet.
--
Rik Wasmus
.
- References:
- passing $_POST variables to classes
- From: amygdala
- Re: passing $_POST variables to classes
- From: Rik
- passing $_POST variables to classes
- Prev by Date: Re: passing $_POST variables to classes
- Next by Date: Re: passing $_POST variables to classes
- Previous by thread: Re: passing $_POST variables to classes
- Next by thread: Re: passing $_POST variables to classes
- Index(es):
Relevant Pages
|