Michael
Michael

Reputation: 4876

CakePHP: How to use (if possible) a class inside both Controller, Model and View?

Supposing I have a StringerHelper(Component|Helper|Behaviour).php class with a method for random strings.

I might need to use this in controllers, models and views. How can I load it wherever I need to ?

Thank you!

Upvotes: 0

Views: 419

Answers (1)

tigrang
tigrang

Reputation: 6767

You would make it a lib and put it in app/Lib. If its simply helper methods, make the methods static.

For 2.x

app/Lib/Stringer.php
App::uses('Stringer', 'Lib');

For 1.x the naming is a bit different

app/lib/stringer.php
App::import('Lib', 'Stringer');

Usage:

Stringer::myHelperMethod([args]);

Upvotes: 2

Related Questions