Creating a custom datasource
This is an open discussion with 6 replies, filed under General.
Search
The easiest thing to do is to create a “normal” Data Source, and modify it to taste.
You can hack most things out, so it may look something like this.
<?php require_once(TOOLKIT . '/class.datasource.php'); Class datasourceSession_Data extends Datasource{ public $dsParamROOTELEMENT = 'session-data'; public function about(){ return array( 'name' => 'Session Data', 'author' => array( 'name' => 'Your Name', 'email' => 'you@yourdomain.com'), ); } public function getSource(){ return '1'; } public function grab(&$param_pool){ $result = new XMLElement($this->dsParamROOTELEMENT); // build XML here return $result; } }
You’d save this file as data.session_data.php
. For building XML you can use Symphony’s own XMLElement
class.
These examples are a great help.
Where abouts in a Data Source does the actual db query take place. Thinking about my comments count post I would like to build a custom data source to handle this.
Would this call take place within grab to then write my values into the xml. Can anyone provide examples of writing your own db queries within Symphony.
This article gives an example of querying the database and adding the results of the query to the XML:
Perfect! I read all the articles apart from this one. Many thanks I look forward to starting my adventure creating custom back end functionally.
can i coulq query database via class.datasource.php in an external .php file?
Create an account or sign in to comment.
Is there a example or tutorial somewhere about creating custom datasources?
I need to load data from a session into a page, and I rather do it through a datasource and set it directly in the HTML then with some Javascript (security). I remember asking this earlier.. but I lost that one.