I am trying to make a virtual attribute with the published assetpath in a model like:
public function getUrlwithassetpath()
{
// First publish the asset
$asset = Asset::register($this);
// get the baseUrl
$pad = $asset->baseUrl;
// strip all (incorrect) paths in the field url
$urlwithoutextension = pathinfo($this->url)['filename'];
// give the correct path back
return $pad."/submap/".$urlwithoutextension;
}
However, the line Asset::register($this) gives an error. I am in a model, not a view, that is why.
But I need the path in this virtual attribute. How can I get the Asset path in a model?
P.S. the topic line is incorrect. This is in the model, not the controller. I can not edit the topic line?
i ended up loading the javascript in a view and find the asset->baseUrl, adding this parameter to the ds.json call back (path=asset->baseUrl) and processing the parameter in the controller.