PHP & AJAX
am 17.01.2008 22:42:45 von KDawg44
Hi,
I have a feeling this is a dumb question, but I am exploring AJAX and
PHP. I would like to write my PHP in an Object Oriented approach.
What is the limitation on what I can return in AJAX? Every example I
find seems to be text, which make sense because it is client side.
So, if I want to try to separate the presentation from the
application, I should call a PHP script using AJAX, and in that PHP
script have objects, call the objects methods and which return to the
PHP script, which returns it to the AJAX script.
So, how do I keep persistent objects throughout the application? Will
each PHP call instantiate a new session or new version of the PHP
script or can I simply put the objects in the $_SESSION?
Thanks for your help as I try to learn/understand this.
Kevin
Re: PHP & AJAX
am 17.01.2008 23:47:30 von Toby A Inkster
KDawg44 wrote:
> So, how do I keep persistent objects throughout the application? Will
> each PHP call instantiate a new session or new version of the PHP script
> or can I simply put the objects in the $_SESSION?
Yes, you may persist objects in $_SESSION.
--
Toby A Inkster BSc (Hons) ARCS
[Geek of HTML/SQL/Perl/PHP/Python/Apache/Linux]
[OS: Linux 2.6.17.14-mm-desktop-9mdvsmp, up 18 days, 10:00.]
Ham vs Bacon vs Pork
http://tobyinkster.co.uk/blog/2008/01/17/pork-etc/
Re: PHP & AJAX
am 18.01.2008 01:14:27 von Jerry Stuckle
KDawg44 wrote:
> Hi,
>
> I have a feeling this is a dumb question, but I am exploring AJAX and
> PHP. I would like to write my PHP in an Object Oriented approach.
> What is the limitation on what I can return in AJAX? Every example I
> find seems to be text, which make sense because it is client side.
> So, if I want to try to separate the presentation from the
> application, I should call a PHP script using AJAX, and in that PHP
> script have objects, call the objects methods and which return to the
> PHP script, which returns it to the AJAX script.
>
> So, how do I keep persistent objects throughout the application? Will
> each PHP call instantiate a new session or new version of the PHP
> script or can I simply put the objects in the $_SESSION?
>
> Thanks for your help as I try to learn/understand this.
>
> Kevin
>
Kevin,
Web pages are transaction oriented. Every call to a web page, whether
it be via AJAX or a browser request, is a new transaction, and has
nothing in it other than what the browser sends.
Typically in web programming, you do not keep persistent objects
throughout the run. Rather, you create them as needed.
Two ways to keep track of things - store things in a cookie (typically
small amounts of text data on the browser) or in the session (text or
binary data). But either way, you don't want to store large amounts of
data, for performance reasons.
You can put objects in the session, as long as they don't contain
resources. But if there is a large amount of data, i.e. from a
database, it's generally better to keep a key in the session and
retrieve the data when it is required.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================
Re: PHP & AJAX
am 18.01.2008 02:13:54 von KDawg44
On Jan 17, 7:14 pm, Jerry Stuckle wrote:
> KDawg44 wrote:
> > Hi,
>
> > I have a feeling this is a dumb question, but I am exploring AJAX and
> > PHP. I would like to write my PHP in an Object Oriented approach.
> > What is the limitation on what I can return in AJAX? Every example I
> > find seems to be text, which make sense because it is client side.
> > So, if I want to try to separate the presentation from the
> > application, I should call a PHP script using AJAX, and in that PHP
> > script have objects, call the objects methods and which return to the
> > PHP script, which returns it to the AJAX script.
>
> > So, how do I keep persistent objects throughout the application? Will
> > each PHP call instantiate a new session or new version of the PHP
> > script or can I simply put the objects in the $_SESSION?
>
> > Thanks for your help as I try to learn/understand this.
>
> > Kevin
>
> Kevin,
>
> Web pages are transaction oriented. Every call to a web page, whether
> it be via AJAX or a browser request, is a new transaction, and has
> nothing in it other than what the browser sends.
>
> Typically in web programming, you do not keep persistent objects
> throughout the run. Rather, you create them as needed.
>
> Two ways to keep track of things - store things in a cookie (typically
> small amounts of text data on the browser) or in the session (text or
> binary data). But either way, you don't want to store large amounts of
> data, for performance reasons.
>
> You can put objects in the session, as long as they don't contain
> resources. But if there is a large amount of data, i.e. from a
> database, it's generally better to keep a key in the session and
> retrieve the data when it is required.
> --
> ==================
> Remove the "x" from my email address
> Jerry Stuckle
> JDS Computer Training Corp.
> jstuck...@attglobal.net
> ==================
Jerry,
Thanks so much for your responses. You are always such a helpful
resource. I understand OO programming but as a young professional
(whose mainstay is sys admin and network engineering and not
programming) unfortunately putting it into practice with databases is
something i have not really done and using OO concepts in web
programming I have not done at all.
So the best bet, if I understand you clearly, is to create a hash
table with a key and some data (whatever the primary key in the DB is
maybe?) that allows me to quickly pull that data from the DB again and
load it back in to the PHP object?
Thanks for the help.
Re: PHP & AJAX
am 18.01.2008 02:33:10 von Jerry Stuckle
KDawg44 wrote:
> On Jan 17, 7:14 pm, Jerry Stuckle wrote:
>> KDawg44 wrote:
>>> Hi,
>>> I have a feeling this is a dumb question, but I am exploring AJAX and
>>> PHP. I would like to write my PHP in an Object Oriented approach.
>>> What is the limitation on what I can return in AJAX? Every example I
>>> find seems to be text, which make sense because it is client side.
>>> So, if I want to try to separate the presentation from the
>>> application, I should call a PHP script using AJAX, and in that PHP
>>> script have objects, call the objects methods and which return to the
>>> PHP script, which returns it to the AJAX script.
>>> So, how do I keep persistent objects throughout the application? Will
>>> each PHP call instantiate a new session or new version of the PHP
>>> script or can I simply put the objects in the $_SESSION?
>>> Thanks for your help as I try to learn/understand this.
>>> Kevin
>> Kevin,
>>
>> Web pages are transaction oriented. Every call to a web page, whether
>> it be via AJAX or a browser request, is a new transaction, and has
>> nothing in it other than what the browser sends.
>>
>> Typically in web programming, you do not keep persistent objects
>> throughout the run. Rather, you create them as needed.
>>
>> Two ways to keep track of things - store things in a cookie (typically
>> small amounts of text data on the browser) or in the session (text or
>> binary data). But either way, you don't want to store large amounts of
>> data, for performance reasons.
>>
>> You can put objects in the session, as long as they don't contain
>> resources. But if there is a large amount of data, i.e. from a
>> database, it's generally better to keep a key in the session and
>> retrieve the data when it is required.
>> --
>> ==================
>> Remove the "x" from my email address
>> Jerry Stuckle
>> JDS Computer Training Corp.
>> jstuck...@attglobal.net
>> ==================
>
> Jerry,
>
> Thanks so much for your responses. You are always such a helpful
> resource. I understand OO programming but as a young professional
> (whose mainstay is sys admin and network engineering and not
> programming) unfortunately putting it into practice with databases is
> something i have not really done and using OO concepts in web
> programming I have not done at all.
>
> So the best bet, if I understand you clearly, is to create a hash
> table with a key and some data (whatever the primary key in the DB is
> maybe?) that allows me to quickly pull that data from the DB again and
> load it back in to the PHP object?
>
> Thanks for the help.
>
That's what I generally do. But no need to create a hash value. Each
table should already have a primary key (typically an automatically
numbered column) which is all you need to identify the data. Just pass
that in the $_SESSION, i.e. as $_SESSION['datakey'];
Transactional programming is quite a bit different from what most
programmers are used to.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
jstucklex@attglobal.net
==================