3068 Posts in 868 Topics by 650 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 833 Views |
-
[Solved] Add Image to DataObjectSet?

25 September 2010 at 1:12am
Hi, I have an SQLQuery which loads a DataObjectSet.
I would like to add an image to the DataObjectSet.
How do I go about it?
All I can do at the moment is add properties such as the file ID and so on, but I would like to be able to say
$MyImage.setWidth(100)
on the template
Any suggestions are more than welcome, I've been trying to do this all day.
-
Re: [Solved] Add Image to DataObjectSet?

25 September 2010 at 1:17am
Hi,
easier to see with the code, but my guess would be to...
foreach ($dosMyDataObjectSet as $doDataObject)
{
$doDataObject->MyImage = DataObject::get_by_id('Image',$doDataObject->ImageID);
} -
Re: [Solved] Add Image to DataObjectSet?

25 September 2010 at 1:23am
the code so far goes like this
class Products extends DataObject{
static $db = array(
"CategoryID" => "Int",
"SubCategory" => "Varchar(80)",
"ProductName" => "Varchar(30)",
"Blurb" => "Text",
"Link" => "Varchar(100)"
);
static $has_one = array(
"ProductImage" => "Image"
);and the query on the Page class goes
$sqlQuery = new SQLQuery();
$sqlQuery->select = array(
"p.*", "f.Filename as Filename", "f.Content as FContent", "f.Title as FTitle",
"@anum := if(@CategoryID = CategoryID, @anum + 1, 1) as row_num",
"@CategoryID := CategoryID as dummy"
);
$sqlQuery->from = array("(SELECT @anum:=0) r,
(SELECT @CategoryID:='') c, Products p left join File f on f.ID = p.ProductImageID");$result = $sqlQuery->execute();
$Products = new DataObjectSet();
foreach($result as $row) {
$Products->push(new ArrayData($row));}
Not sure about this "Image" in your suggestion. Is that like "File"?
-
Re: [Solved] Add Image to DataObjectSet?

25 September 2010 at 1:35am Last edited: 25 September 2010 1:36am
I see, or rather I don't see, what your sql is doing. But I think what I've given will help... this may help explain it
controller...
function MyProducts()
{
return DataObject::get('Products ');
}template...
<% control MyProducts %>
$ID
<% control ProductImage %>
<% control CroppedImage(173,106) %>
<img src="$URL" alt="$Title" />
<% end_control %>
<% end_control %>
<% end_control %>and yes Image is an extension of File
-
Re: [Solved] Add Image to DataObjectSet?

25 September 2010 at 1:43am
Yes!
Thank you so much, that definitely worked! *whew* I've been stuck on that for the past 14 hours.
The SQL is adding a row number to each record within a product category.
I want to be able to have a heading everytime a product category changes, and with that SQL I can set the template to say something like
<% if rec_num=1%>
<h2>$ProductCategory</h2>
<% end_if %>
| 833 Views | ||
|
Page:
1
|
Go to Top |


