Hi
So I have to integrate Silverstripe with an external database.
I did this following the answers from this forum post
http://www.silverstripe.com/extending-hacking-silverstripe-forum/flat/120
On the ProductPage_Controller class I have the following function:
function Products($num=5) {
$db = new MySQLDatabase(array("server" => "localhost","username" => "root","password" => "","database" => "prods" ));
$query = $db->query("SELECT * FROM products");
$result = new DataObjectSet();
foreach($query as $row) {
//Debug::show($row);
$a = new MyProduct($row);
//Debug::show($a);
$result->push($a);
}
If I use the debug function on the $row, I can see the data.
Then I create a class MyProduct extends ViewableData
So I can put the data in Silverstripe objects
My question is where and how should I define the fields for MyProduct object?
Also I have a ProductPage.ss file where I have a <% control Products %> call.
This will call the Products function and if I have for example 3 products, It will iterate 3 times.
If inside the <% control Products %> I write $name (a field returned by the SQL) it doesn't show anything, probably because I didn't define the fields of MyProduct object.
I hope this is a clear picture of my situation.
Thanks for the help
Daniel