473,386 Members | 1,647 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Wrangling Javascript from PHP

I'm working on a bunch of classes in PHP that will render into HTML
a-la widgets. Part of this functionality is that I'd like to expose
Javascript in the classes and have each instance provide and/or
generate the needed code along with the HTML.

I've done a lot of server side generating and program state hackery
so...I'm not totally unfamiliar. I already have some javascript
functionality from the dojo toolkit, so I have a nice set of functions
to work with.

What I'd like is perhaps some input or a discussion on what could be
some best practices in achieving this with PHP.

For example,
Maybe I'll have to ask each object for the javascript code they want to
provide before rendering the final page and place it at the top of the
page?
The most complicated question is how will I expose all the events and
scenarios I want to have my classes generate code for? In PHP, what is
the best way to code a model to allow instantiated objects to perform a
"when this is clicked, do this with this object over here"? Smells
like an event-handling model, but that doesn't exist in PHP. And I
certainly don't want to have to go subclassing every widget I use for
each page! Hah.

Details, options and the implications of each one are really what I'd
like to explore...

Thanks to all who reply!

Jul 26 '06 #1
2 1124


Well to me if you are going to talk about event handling you need to
think Ajax. There are frameworks out there to do just what you are
talking about.
On 2006-07-26 15:32:42 +0100, "Omega" <at******@gmail.comsaid:
I'm working on a bunch of classes in PHP that will render into HTML
a-la widgets. Part of this functionality is that I'd like to expose
Javascript in the classes and have each instance provide and/or
generate the needed code along with the HTML.

I've done a lot of server side generating and program state hackery
so...I'm not totally unfamiliar. I already have some javascript
functionality from the dojo toolkit, so I have a nice set of functions
to work with.

What I'd like is perhaps some input or a discussion on what could be
some best practices in achieving this with PHP.

For example,
Maybe I'll have to ask each object for the javascript code they want to
provide before rendering the final page and place it at the top of the
page?
The most complicated question is how will I expose all the events and
scenarios I want to have my classes generate code for? In PHP, what is
the best way to code a model to allow instantiated objects to perform a
"when this is clicked, do this with this object over here"? Smells
like an event-handling model, but that doesn't exist in PHP. And I
certainly don't want to have to go subclassing every widget I use for
each page! Hah.

Details, options and the implications of each one are really what I'd
like to explore...

Thanks to all who reply!

Jul 26 '06 #2
That doesn't target the problem I have outlined.

What I'm after is a way of essentially coding PHP objects that then get
rendered into HTML AND Javascript.

The dojo toolkit I mentioned is one such framework but does not provide
the solution I am looking for. You may be better served by re-reading
my question again. Should you need any clarification, please ask as
I'm sure it would help others.

Richard Hulbert wrote:
Well to me if you are going to talk about event handling you need to
think Ajax. There are frameworks out there to do just what you are
talking about.
On 2006-07-26 15:32:42 +0100, "Omega" <at******@gmail.comsaid:
I'm working on a bunch of classes in PHP that will render into HTML
a-la widgets. Part of this functionality is that I'd like to expose
Javascript in the classes and have each instance provide and/or
generate the needed code along with the HTML.

I've done a lot of server side generating and program state hackery
so...I'm not totally unfamiliar. I already have some javascript
functionality from the dojo toolkit, so I have a nice set of functions
to work with.

What I'd like is perhaps some input or a discussion on what could be
some best practices in achieving this with PHP.

For example,
Maybe I'll have to ask each object for the javascript code they want to
provide before rendering the final page and place it at the top of the
page?
The most complicated question is how will I expose all the events and
scenarios I want to have my classes generate code for? In PHP, what is
the best way to code a model to allow instantiated objects to perform a
"when this is clicked, do this with this object over here"? Smells
like an event-handling model, but that doesn't exist in PHP. And I
certainly don't want to have to go subclassing every widget I use for
each page! Hah.

Details, options and the implications of each one are really what I'd
like to explore...

Thanks to all who reply!
Jul 26 '06 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.