Silverstripe Version:3.1
How can I add an attribute/property (does not exit in the DB) to an object and be able to access it in a template
I have the following declaration for my product model
class Product extends SlugModel {
private static $db = array(
'Name' => 'Varchar(200)',
'Code' => 'Varchar(200)',
);
}
I have another script looping through the product and setting a “Large” attribute
public function ProdList() {
$products = $this->Products()->column('ID');
$large_product_ids = array(1,2,3);
foreach($products as $p){
if (in_array($p->ID, $large_product_ids)){
$p->update(array('Large'=>'Y'));
} else {
$p->update(array('Large'=>'N'));
}
}
return $products;
}
I have tried to access the Large attribute in the ss file, but I get a blank value. How can I access the Large value??
<% loop $ProdList %>
$Name $Large
<% end_loop %>
I do not want to add the Large attribute to the Product model.