Jump to content


einsteinsboi

Member Since 18 May 2012
Offline Last Active Apr 21 2013 02:13 PM
-----

Posts I've Made

In Topic: ProcessWire Conference 2013 / London / Cambridge

15 October 2012 - 05:46 AM

I'd love to go depending on cost, but I'm in New Zealand so everywhere is far away, except Australia ofcourse

In Topic: Integrating a member / visitor login form

01 September 2012 - 04:51 PM

Epic! :)

In Topic: Reading and displaying data from a custom table

22 August 2012 - 08:23 PM

Ah, this does make a lot of sense and a perfect fit for PW. Import the xml data feed entries as PW pages and keep up to date via a cronjob. In this case i wouldn't go for a separate database.
Create a template "feed_item". Add fields to the template that map to corresponding data you want to import from the xml feed. You can add as many of your own fields to go next to that. For the actual importing/updating you can write something yourself with the PW API, i'm a noob so can't really help you there but i'm sure Ryan or other veterans can help. You could also take a look a look at this (alpha) module for some inspiration or maybe it works for your use case:

http://modules.proce...ss-data-import/
http://processwire.c...ller/#entry1647

Using this approach you eventually have all of the feed data and your own added fields as PW pages/data. From there you can display and do with it whatever you want.


THANK YOU to you and Ryan I now have a much better approach to my problem :)

In Topic: Reading and displaying data from a custom table

22 August 2012 - 08:19 PM

This is brilliant Ryan! :) Thank you so much, can't wait to play with this example and then adapt it to my needs. My vendor's feed comes in XML format so I'll work with that for now and then see if I can't convince them to use JSON.

I had thought that using the db was the best approach but I see that this may be even better and more efficient. I will work on this and report back :)

In Topic: Reading and displaying data from a custom table

21 August 2012 - 11:21 PM

Ryan, thank you for your input. This looks promising :) I've responded to specifics below:

This sounds like a fun project! Does the data need to stay in this external table, or can it live in ProcessWire instead?


My thought was to put the data into the Processwire database but in its own table so that any updates to PW don't interfere with the custom data. Is this what you mean?

If the data can live in ProcessWire, your cron job could very easily update the data by just bootstrapping ProcessWire. Bootstrapping is as simple as: include("/path/to/pw/index.php"); One-time importing data from an external source is also very easy to do via the API. So if you can do it, I would just let the data live in ProcessWire instead of an external database, and it'll make the whole job a piece of cake.


I like the idea of "piece of cake" :) Can you explain this a bit more? I'm not quite familiar with bootstrapping PW yet :huh:


But if that data needs to stay external, then Sinnut's solution is a good way to go. You would use the DB's primary key (or some other unique column) to serve as the urlSegment that loads the page. You'd setup one page/template to handle all that data, and it would find it like this:

$key = (int) $input->urlSegment1;
if(!$key) throw new Wire404Exception();

$result = $yourDB->query("SELECT make, model, year FROM your_table WHERE id=$key");
if(!$item->num_rows) throw new Wire404Exception();

list($make, $model, $year) = $result->fetch_row();

echo "<ul>";
echo "<li>Make: $make</li>";
echo "<li>Model: $model</li>";
echo "<li>Year: $year</li>";
echo "</ul>";

Note: enable URL segments on the template where this code is (on the URLs tab), as URL segments are not enabled by default.



This is another reason why it may make a lot of sense to keep all the data in ProcessWire. But if you can't do that, it won't be a problem: all you need is for your pages to contain a reference to the primary key of row they map to in your external table. I would suggest using the built-in "name" field for those pages to map to the primary key in your external table, because you know it'll be unique and relevant. But you could always create a separate integer or text field in ProcessWire do handle it too. But lets say you use 'name', then your page templates could load the data like this:

$result = $yourDB->query("SELECT make, model,year FROM your_table WHERE id='{$page->name}'");


Thanks again, I will play with this code and see what I get :) So far I've only built really simple sites with PW so I'm pretty excited about doing some more indepth stuff and getting my hands dirty with some PHP and the API :)

Hi, iensteinsboi and welcome!
I remember reading your tutorials while learning basics of MODx. Thank you! They were very helpful.
You will be amazed of simplicity of ProcessWire and really friendly community here and hope you will soon become a convert. Yeah, I know you love both Drupal and MODx, but I'm sure you will fall in love with ProcessWire as well :)


Thanks for the welcome :) Glad you found the tuts useful. I'm already sold on PW :) I've built a few simple sites with it and understand the basics, but I'm looking to delve deeper now, play with the API and do some more complex stuff.