Forums / Developer / How can i add Java Script + PHP to a single web page?

How can i add Java Script + PHP to a single web page?

Author Message

Lupusoru Razvan

Wednesday 16 December 2009 9:56:02 am

Hi,

I have this interractive map.It is built in java and needs to use PHP to import some data from MySQL.All examples i have seen are built using templates. I donn't need anything fancy.I only have this single page and nothing else. I tryed adding code between the 'literal' tags in the page editor, but the code is duplayed and i get an error like <script> tag not recognised.

Thanks

Gaetano Giunta

Wednesday 16 December 2009 3:17:10 pm

You will need to create either

- a new template operator

- a new template function

- a custom module and view

the standard way of operation of eZ Publish is "no way to execute php from templates"

Principal Consultant International Business
Member of the Community Project Board

Nicolas Pastorino

Monday 25 January 2010 1:34:40 pm

Hi and welcome in the eZ Community,

Resuscitating this slightly old topic, could you describe a bit more what your application would consist of ?

What kind of data do you need to push to the interactive map ?
How is the data represented in the backend (using the content engine or not, if yes what datatypes, etc..) ?
Is data stored in eZ Publish at all ?

Let us know,
Cheers,

--
Nicolas Pastorino
Director Community - eZ
Member of the Community Project Board

eZ Publish Community on twitter: http://twitter.com/ezcommunity

t : http://twitter.com/jeanvoye
G+ : http://plus.tl/jeanvoye

Brandon Chambers

Monday 25 January 2010 3:12:04 pm

Nicolas is right, the standard way of interacting/working with eZ is to use higher-level languages such as the template code and HTML. Although, you can create new modules and extensions which usually involve using PHP/JavaScript/XML for more technical interactions with eZ. Otherwise the functionality you need can probably be used with eZ Publish "right out of the box".

Furthermore, I recently had a project in which I used the Google JavaScript API for converting a rough-sketch interaction you are talking about to a more elegant solution for a client. The pre-existing solution involved using a separate database to store business locations and their information (phoone number, street address, URL, etc).

So the interaction model looks like this:

> User enters City/State into search field and selects a distance radius in miles (it's an American-based client)

> On submission, JavaScript function is called

> Call Google API

> Call PHP class for AJAX interaction (to populate map with location information)

> PHP class queries database to retrieve data based on user input (calculates radius and whatnot as well)

> Save information to XML object

> return XML object tp JavaScript

> Populate map with retrieved information

This can be done using a simple template override and no template code as you asked..

Again, a more elaborate solution might involve the GMaps location object (an extension) with eZ Find. I think that would match the eZ Publish interaction model a bit closer, make your code more readable, as well as debugging much easier all because this solution would have a much clearer segmentation of code.

Good luck and I hope this helps.

Brandon Chambers
brandon@granitehorizon.com
blog: http://blog.divdesigns.com
Granite Horizon / http://granitehorizon.com

Sergi A

Wednesday 10 February 2010 1:21:23 am

"

Furthermore, I recently had a project in which I used the Google JavaScript API for converting a rough-sketch interaction you are talking about to a more elegant solution for a client. The pre-existing solution involved using a separate database to store business locations and their information (phoone number, street address, URL, etc).

So the interaction model looks like this:

> User enters City/State into search field and selects a distance radius in miles (it's an American-based client)

> On submission, JavaScript function is called

> Call Google API

> Call PHP class for AJAX interaction (to populate map with location information)

> PHP class queries database to retrieve data based on user input (calculates radius and whatnot as well)

> Save information to XML object

> return XML object tp JavaScript

> Populate map with retrieved information

This can be done using a simple template override and no template code as you asked..

"

That's very similar to my case... I have the picture but i don't know exactly where to start.. i mean, i have an ajax call using the GMaps API GDownload function:

GDownloadUrl(url, function(...) ...

the 'url' should be a php script that would retrieve information from database and return it in xml ... but how can I do it taking into account the ezPublish model... should the PHP be a class, where should it be located, and how can I interact with the database directly?

thank you,

Sergi.