Cakephp ClassRegistry::init in bootstrap
Asked Answered
B

2

6

can I use a model in bootstrap.php to get an array with find() from database ?

like this :

$Setting = ClassRegistry::init('Setting');
$Settings = $Setting->find('all');

thanks

Buckjumper answered 12/4, 2012 at 11:31 Comment(4)
well then you shoudnt ask if thats possible but display the errors you got (which you must have gotten because you are asking). try to be as specific as possible.Glenoid
@Glenoid you say its not possible ?Buckjumper
i have this error : Fatal error: Class 'ClassRegistry' not foundBuckjumper
now that it more helpful to us, of course :)Glenoid
G
10

You need to manually load the used classes then, if you really must use core internal stuff that early.

try

App::uses('ClassRegistry', 'Utility');

before you actually use ClassRegistry.

Glenoid answered 12/4, 2012 at 12:36 Comment(1)
now is it correct job ? ( i'm use it for load site settings from database and cache them )Buckjumper
F
2

Write in bootstrap.php

App::uses('ClassRegistry', 'Utility');
$Setting = ClassRegistry::init('ModelName');
Frambesia answered 27/6, 2015 at 6:7 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.