I'm using a third party library to format data in a specific way. I managed to create a component from that library doing the following:
App::uses('Component', 'Controller');
App::import('Vendor','csformat' ,array('file'=>'csformat'.DS.'csformat.php'));
class CSFormatComponent extends Component {
public function startup(Controller $controller){
$controller->CSF = new csfStartup(null);
return $controller->CSF;
}
}
Doing that allows me to access different classes provided by the library through my controller. But I realized that I'll be doing a lot of unnecessary $this->set($one, $two)
to pass formatted data from controllers to views where essentially the library could be much more beneficial as a helper since I can just format my data on the views.
Any ideas how to create such helper?
Update:
Per Kai
's recommendation from the comment below, I have created a bare-bones helper that App::import
s the vendor library and included the helper where needed in my controllers therefore providing me access to the library in my views.
My issue now is that I don't want to be constantly instantiating the library's csfStartup
class in every view.
Is there a way to have my helper readily provide an instance of that class when the helper is called? Similar to the way my component was working.