3093 Posts in 875 Topics by 654 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 357 Views |
-
Querying edited content in custom function.

12 July 2011 at 6:26am
If anybody could help, it'd be much appreciated. I'm trying to query for content that would be edited in the CMS of Silverstripe, but not within my page.ss I want the content that is edited to display in accordance with a day function code that I wrote. That way someone can edit the content specifically for every monday weekly, tuesday, wednesday- and so forth. I'm currently having trouble cause I'm not sure what to call. But, this is my code for it.
For example:
<?php
/**
* Defines the HomePage page type
*/class HomePage extends Page {
static $db = array(
'HSun' => 'HTMLText',
'HMon' => 'HTMLText'
);static $has_one =array(
);
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root', new TabSet('Daily'));
$fields->addFieldToTab('Root.Daily.Sunday', new HTMLEditorField('HSun', 'Sunday Service'));
$fields->addFieldToTab('Root.Daily.Monday', new HTMlEditorField('HMon', 'Monday Service'));
return $fields;
}}
class HomePage_Controller extends Page_Controller {function days() {
date_default_timezone_set("America/Los_Angeles");
$sunday = '0';
$monday = '1';
$tueday = '2';
$wednesday = '3';
$thursday = '4';
$friday = '5';
$saturday = '6';$today = date("w");
$CT = "Current Time: ".date("G:i");
$wed = DB::get($HSun);
//return "$today";
return $wed;
}
}If anybody knows how to query it correctly, that'd be great, because that doesn't work at all, and I can't seem to figure it out...
-
Re: Querying edited content in custom function.

12 July 2011 at 6:30pm
$wed = DB::get($HSun);
You'd be getting an error on that, HSun isn't defined as a variable.
If I understand correctly, you want separate HTMLText fields for each day of the week? and in that case I'd do something like
switch($today) {
case '0':
return $this->dbObject('HSun');
case '1':
return $this->dbObject('HMon');
....
}$this->dbObject('Foo') returns the Database field object, were as $this->Foo will return just the value inside that field. Usually the object is more useful to have.
-
Re: Querying edited content in custom function.

13 July 2011 at 4:26am
Hey Willr,
thank you so much. That was the perfect thing I needed to know.
Secondly, thanks for the switch technique, my original one was having trouble with the days so I decided to use the switch technique and it's all functioning perfectly now. Thank you very much.Out of curiosity, is it hard to add an $has_one piece into that return as well? I was considering using the $has_one to allow image uploading to a ImageField in silverstripe. Would I produce that the same way, or would the code be different?
Once more, thanks for all your help.
-Hibari
| 357 Views | ||
|
Page:
1
|
Go to Top |


