17488 Posts in 4473 Topics by 1978 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 1380 Views |
-
How can I determine if a image is set

21 July 2007 at 10:14am Last edited: 21 July 2007 10:15am
I created an image in the "ItemPage extends Page" static $has_one array
static $has_one = array( 'BannerImg' => 'Image' );
but I want to be able to use a default image if the image
has not been set. How can I do that?
I am trying to create a function in the "ItemPage_Controller extends Page_Controller"
but I can't determine in the function if "BannerImg" is actually
set. I tried using:
isset($this->BannerImg) always returns true
strlen($this->BannerImg) always returns false
$this->BannerImg.length always returns a non-zero value
sizeof($thisBannerImg) always returns zero -
Re: How can I determine if a image is set

21 July 2007 at 10:27am Last edited: 21 July 2007 10:29am
[code php]
if ($this->BannerImgID > 0) {
// image is set
} else {
// image is not set
}or, you can try in the template, but I am not sure, if it works
<% if BannerImg %>
$BannerImg
<% else %>
<img src="default.png"/>
<% end_if %> -
Re: How can I determine if a image is set

21 July 2007 at 1:27pm
<% if BannerImg %>
$BannerImg
<% else %>
<img src=\"default.png\"/>
<% end_if %>should work fine btw, we use that method quite alot
-
Re: How can I determine if a image is set

21 July 2007 at 1:50pm
Thanks
Both methods worked. The second method <% if BannerImg %> is what I really
wanted but I guess as a newbee I was trying to mix <% control Level() %> and
getting it wrong.On the first method, where is it Documented about the BannerImgID? Do
all created Fields have that (ie. <field>ID)? -
Re: How can I determine if a image is set

22 July 2007 at 2:21pm
"On the first method, where is it Documented about the BannerImgID? Do
all created Fields have that (ie. <field>ID)?"Not all fields, Banner ID does as its a has_one. This page may help - http://doc.silverstripe.com/doku.php?id=datamodel
"Define 1-to-1 joins in $has_one. The LHS is the relationship name, the RHS is the class you're linking to. This will create a field called (relationship-name)ID, e.g., [[ParentID]]." or in your case BannerID
| 1380 Views | ||
|
Page:
1
|
Go to Top |


