3070 Posts in 869 Topics by 651 members
|
Page:
1
|
Go to End | |
| Author | Topic: | 252 Views |
-
SS3 Adding data to DataObject in page controller

23 July 2012 at 8:38pm
Hey guys,
Before SS3, I could load in a dataobject and loop through each item adding fields on the fly which could then be used in the template.
I can't seem to get this working in SS3, any ideas why?
public function Shops(){
$Shops = Shop::get();
foreach($Shops as &$Shop) {
$Shop->URL = trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($Shop->Title)), '-');
}
return $Shops;
} -
Re: SS3 Adding data to DataObject in page controller

23 July 2012 at 10:57pm
Why would you iterate over the set only to iterate over it again most likely in your template?
A better way to structure it would be to add a method to your Shop object which encapsulates this functionality.
public function getURL() {
return trim(preg_replace('/[^a-z0-9]+/', '-', strtolower($Shop->Title)), '-');
}Then you can use $URL where you require, not just that template.
| 252 Views | ||
|
Page:
1
|
Go to Top |


