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.

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 30 2025 19:52:06
Script start
Timing: Jan 30 2025 19:52:07
Module start 'layout'
Timing: Jan 30 2025 19:52:07
Module start 'content'
Timing: Jan 30 2025 19:52:07
Module end 'content'
Timing: Jan 30 2025 19:52:07
Script end

Main resources:

Total runtime0.0258 sec
Peak memory usage4,096.0000 KB
Database Queries3

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0076 588.2656151.2266
Module start 'layout' 0.00760.0052 739.4922220.7344
Module start 'content' 0.01280.0116 960.22661,005.9453
Module end 'content' 0.02440.0013 1,966.171937.9922
Script end 0.0257  2,004.1641 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.002810.7267140.0002
Check MTime0.00104.0613140.0001
Mysql Total
Database connection0.00082.923510.0008
Mysqli_queries0.005119.740830.0017
Looping result0.00000.063010.0000
Template Total0.00093.710.0009
Template load0.00083.008710.0008
Template processing0.00020.644310.0002
Override
Cache load0.00052.072810.0005
General
dbfile0.00093.646580.0001
String conversion0.00000.043540.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 1
 Number of unique templates used: 1

Time used to render debug report: 0.0001 secs