I'm using CakePHP and was previously just storing sitewide methods in AppController, but when I call them from within my model, it just doesn't seem right. Should they be put in my AppModel instead?
Asked
Active
Viewed 156 times
1 Answers
0
You could store them in Lib:
App/Lib/GlobalMethods.php
AppController.php :
App::import('Lib', 'GlobalMethods');
class AppController extends Controller {
}

Tim Joyce
- 4,487
- 5
- 34
- 50
-
Would I just extend AppController from within GlobalMethods? e.g. `class GlobalMethods extends AppController {}` ? – bob_cobb Dec 30 '12 at 18:00
-
I was assuming you were looking to store some convenience functions. What kind of methods are you referring to? you should update your question. Lib is generally meant for cf's or third party scripts. Sounds like you may be looking to create a component. This answer here had a good suggestion to create a layer between appController and controller: http://stackoverflow.com/questions/1875831/cakephp-abstracting-appcontroller-another-level-possible – Tim Joyce Dec 30 '12 at 18:07
-
1there is no App::import for 2.x internal classes anymore, only for vendor classes. So more like App::uses('GlobalMethods', 'Lib') – mark Dec 30 '12 at 18:59
-
Can you link to the documentation on this @mark? I have a couple 2.x apps using import on the Lib files and haven't run into any problems yet. – Tim Joyce Dec 31 '12 at 10:41
-
its just deprecated - not totally removed yet for BC. but the 2.x documentation should already state the new correct way. – mark Jan 01 '13 at 20:14