views:

9

answers:

1

Hi just need to know whether you can query the database from inside a helper class, whether you should and how you do it.

Thanks

+1  A: 

You could, by passing a reference to the Model into the View as a variable via $this->set() and then querying it...but you shouldn't. It's messy ;-)

CakePHP uses the MVC model, and helpers are part of the View (the V of MVC) - their job is purely to display the (already available) information passed to it from the controller.

If your view needs extra information , then your controller should have already queried the Models to get it.

I'd suggest you read up on the MVC model if you're not familiar with it, then some refactoring might be in order!

AdamGiles