Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

Customising the CMS /

Image feild question.


Reply


695 Views

Avatar
Daimz

Community Member, 36 Posts

1 August 2009 at 1:44pm

I have just notice a slight problem in how I have set up my image feilds. I am building a portfolio site and I wanted to have images that would be added to a featured section on the site which I did like this:

PortfolioPage.php

<?php
/**
* Defines the ArticlePage page type
*/
class PortfolioPage extends Page {
   static $db = array(
'Date' => 'Date',
'Author' => 'Text',
'Client' => 'Text',
'Task' => 'Text',
'Role' => 'Text'
);
static $has_one = array(
'FeatureWork' => 'PortfolioPage_FeatureWork',
'RecentThumb' => 'PortfolioPage_RecentThumb',
'PortImage' => 'Image'
);
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 TextField('Client'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Task'), 'Content');
$fields->addFieldToTab('Root.Content.Main', new TextField('Role'), 'Content');
$fields->addFieldToTab('Root.Content.Images', new ImageField('FeatureWork'));
$fields->addFieldToTab('Root.Content.Images', new ImageField('RecentThumb'));
$fields->addFieldToTab('Root.Content.Images', new ImageField('PortImage'));
   
return $fields;
}

static $icon = "themes/tutorial/images/treeicons/news";

static $defaults = array(
'ProvideComments' => true
);

}

class PortfolioPage_Controller extends Page_Controller {

}

class PortfolioPage_FeatureWork extends Image {

function generatePortfolioFeature($gd) {
$gd->setQuality(100);
return $gd;
}
}
class PortfolioPage_RecentThumb extends Image {

function generatePortfolioRecentThumbnail($gd) {
$gd->setQuality(100);
return $gd;
}
}

?>
HomePage.php

<?php
/**
* Defines the HomePage page type
*/

class HomePage extends Page {
static $db = array(
);
static $has_one = array(
);
static $allowed_children = array('PortfolioPage');

static $icon = "themes/tutorial/images/treeicons/home";
}

class HomePage_Controller extends Page_Controller {

/*Function calls Articles on to the homepage showing only the first Paragraph*/

function LatestNews($num=5) {
$news = DataObject::get_one("PortfolioHolder");
return ($news) ? DataObject::get("PortfolioPage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
}
function RecentPortfolioUpdate($num=4) {
$news = DataObject::get_one("PortfolioHolder");
return ($news) ? DataObject::get("PortfolioPage", "ParentID = $news->ID", "Date DESC", "", $num) : false;
}

   
}
?>

HomePage.ss

<div id="feature">
<% control LatestNews %>
<a href="$Link" title="Read more on &quot;{$Title}&quot;"><img src="$FeatureWork.PortfolioFeature.URL" id="feature_image"></a>
<% end_control %>
</div>

All this does as it is meant to and shows the images in the FeatureWork ImageFeild where they should be in the jQuery as you can see [url =http://www.arctosdesign.com/silverstripe/]HERE[/url]. However my problem is that because it is a featured section I only want it to show pages where I have actually uploaded a image in the FeatureWork ImageFeild. Oviously every time I create a new PortfolioPage I will have that image field their but I wont always be adding an image to it, and at the moment when I dont I get an empty block in the image slider because it wants to add an image.