Hello,
I would like to display an Image which doesn't exist in my database : ilt's a default Image. its path can be defined in my _config.php. But my Image isn't display :'(
My PHP code :
class NewsPage extends Page {
static $icon = "news/images/treeicons/news";
public static $db = array(
'Date' => 'Date',
'Author' => 'Text'
);
public static $has_one = array(
'Thumbnail' => 'Image'
);
static $can_be_root = false;
static $default_parent = "NewsHolder";
static $defaultThumbnail = true;
static $defaultThumbnail_path = "news/images/default-thumbnail.jpg";
function getCMSFields() {
$fields = parent::getCMSFields();
$fields->addFieldToTab('Root.Content.Main',
new CalendarDateField('Date'),
'Content');
$fields->addFieldToTab('Root.Content.Main',
new TextField('Author'),
'Content');
$fields->addFieldtoTab('Root.Content.Main',
new ImageField('Thumbnail'),
'Content');
return $fields;
}
function getThumbnailOrDefault() {
$thumbnail = DataObject::get_by_id("Image", $this->ThumbnailID);
if($thumbnail) {
return $thumbnail;
}
elseif(self::$defaultThumbnail) {
$t = singleton("Image");
$t->setFilename(self::$defaultThumbnail_path);
return $t;
}
else {
return false;
}
}
}
class NewsPage_Controller extends Page_Controller {
}
My template code :
...
<h1>
<% if ThumbnailOrDefault %>
<% control ThumbnailOrDefault %>
<% control PaddedImage(69,46) %>
<img class="vignette" src="$URL" width="69" height="46" alt="$Title" title="$Title" />
<% end_control %>
<% end_control %>
<% end_if %>
<a href="$Link">$Date.Nice - $Title.XML</a>
</h1>
...
thanks for your help,