5102 Posts in 1520 Topics by 1116 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 758 Views |
-
Accessing database from page

27 March 2009 at 12:54am
Hey
Iv got a module or managing activities with the following fields:
static $db = array(
'Name' => 'Text',
'Price' => 'Int',
'CategoryID' => 'Text',
'Type' => 'Text',
'Description' => 'Text',
'Parties' => 'Text',
'ImageURL'=>'Text'
);everythings working fine on the admin side activities can be added, edited and deleted.
But what i want to do is loop through all the activities with a categoryId of 1, somthing like
<%control Activity %>
<p>$Name</p>
<% end_control %>any ideas on how i would achieve this as i cant seem to use DataObject inside my page.php
Thanks
-
Re: Accessing database from page

27 March 2009 at 3:32am
hi iv got a steg closer with
function phill_test()
{
$SQL_id = (int) 1;
$page = DataObject::get('SiteTree');
return $page;
}this works displaying a list of all the pages but if i change SiteTree to Activities it doesnt anything (rest of page still dislpays fine) but there are entries in the db, any ideas on what im doing wrong?, is there possible anything i need to add to the activities class?
thanks again
-
Re: Accessing database from page

27 March 2009 at 8:30am
Is CategoryID supposed to be text?
Your function should look something like this:
function getActivitiesWithCategory($category = "") {
$category_SQL = Convert::raw2sql($category);
return DataObject::get("Activities", "CategoryID = '{$category_SQL}'");
}In your template, you can then call:
<% control ActivitiesWithCategory(SomeCategoryName) %>
This activity is called $Name
<% end_control %> -
Re: Accessing database from page

28 March 2009 at 12:07am
Thanks iv been able to solve the problem with your code
| 758 Views | ||
|
Page:
1
|
Go to Top |


