# |
Aug 9th 2008, 18:05 |
TommyO |
and use it right away |
# |
Aug 9th 2008, 18:05 |
jaredhoyt |
TommyO: he's wanting to be able to use it class-wide though w/o having to instantiate it everytime |
# |
Aug 9th 2008, 18:05 |
TommyO |
$User = instead of $this->User = |
# |
Aug 9th 2008, 18:05 |
TommyO |
don't assign it to a class value like that as it will interfere with the controller's expectation of that member |
# |
Aug 9th 2008, 18:04 |
jaredhoyt |
i haven't tried calling the method from a normal controller's beforeFilter... just a controller's method |
# |
Aug 9th 2008, 18:04 |
jaredhoyt |
well actually i take that back |
# |
Aug 9th 2008, 18:04 |
jezek |
mm |
# |
Aug 9th 2008, 18:04 |
jaredhoyt |
if you do it in a normal controller's beforeFilter(), it is |
# |
Aug 9th 2008, 18:04 |
jaredhoyt |
TommyO: right, his problem is... if you do $this->User = ClassRegistry::init('User'); in Component::startup() and call the method that uses $this->User in AppController::beforeFilter ... the User model isn't loaded |
# |
Aug 9th 2008, 18:03 |
TommyO |
jezek: ^^ this applies to you too :) |
# |
Aug 9th 2008, 18:03 |
TommyO |
or to turn it off, like $this->Component->enabled = false; |
# |
Aug 9th 2008, 18:02 |
TommyO |
*you do |
# |
Aug 9th 2008, 18:02 |
TommyO |
that way beforeFilter can be used to give the component settings, like yo udo for Auth |
# |
Aug 9th 2008, 18:02 |
TommyO |
jaredhoyt: the process is: Component::initialize(); Controller::beforeFilter(); Component::startup(); Controller::action(); Controller::beforeRender(); |
# |
Aug 9th 2008, 17:58 |
jezek |
oh |
# |
Aug 9th 2008, 17:58 |
jaredhoyt |
i don't know why though because i don't know enough about the class registry =P |
# |
Aug 9th 2008, 17:58 |
jaredhoyt |
i just tried an arbitrary example and it fails from beforeFilter() but works from beforeRender() |
# |
Aug 9th 2008, 17:58 |
jezek |
hmm |
# |
Aug 9th 2008, 17:57 |
jaredhoyt |
hmm, you're right, it does make a different if the component's method is being called from app controller's beforeFilter() |
# |
Aug 9th 2008, 17:53 |
jezek |
i copied and psted what you wrote |
# |
Aug 9th 2008, 17:53 |
jezek |
Call to a member function findById() on a non-object |
# |
Aug 9th 2008, 17:52 |
jaredhoyt |
i don't think it would make a difference |
# |
Aug 9th 2008, 17:51 |
jezek |
if it makes any difference, i'm including the component in app_controller |
# |
Aug 9th 2008, 17:51 |
jaredhoyt |
i added $this->User = ClassRegistry::init('User'); to a component startup and pr($this->User->findById(1)); to the method, and it worked just fine |
# |
Aug 9th 2008, 17:51 |
jezek |
mm |
# |
Aug 9th 2008, 17:51 |
jezek |
really |
# |
Aug 9th 2008, 17:50 |
jaredhoyt |
clear your cache maybe |
# |
Aug 9th 2008, 17:50 |
jaredhoyt |
hmm, works fine for me |
# |
Aug 9th 2008, 17:48 |
jezek |
null |
# |
Aug 9th 2008, 17:45 |
jaredhoyt |
yeah, try http://bin.cakephp.org/view/1303690479 |
# |
Aug 9th 2008, 17:43 |
jezek |
nope |
# |
Aug 9th 2008, 17:43 |
jaredhoyt |
are you defining the variable outside of startup() as well? like $userInstance = null; or whatever |
# |
Aug 9th 2008, 17:42 |
jezek |
ok |
# |
Aug 9th 2008, 17:41 |
jaredhoyt |
or whatever model it is |
# |
Aug 9th 2008, 17:41 |
jezek |
the name of the variable? |
# |
Aug 9th 2008, 17:41 |
jaredhoyt |
don't know if it loads it automatically into the class with the same name... try $this->userInstance = ... |
# |
Aug 9th 2008, 17:41 |
jaredhoyt |
maybe try changing the name... i'm not 100% how init() works... |
# |
Aug 9th 2008, 17:41 |
jezek |
yeah it works fine that way |
# |
Aug 9th 2008, 17:40 |
jaredhoyt |
like it is in the manual |
# |
Aug 9th 2008, 17:39 |
jaredhoyt |
jezek: did you try just instantiating the model in the method first? |
# |
Aug 9th 2008, 17:39 |
JD__ |
so it looks llke i need to make a new profile object, load the data, run validation, then resave everything else |