0
votes

This is a very general Cakephp question. I'm attempting to combine the model data from many different models into a given page.

I'm building a simple content-manager for my boss's online-CV so he can manage it from a simple GUI. So I have models for all the different sections of the CV, but need to combine the data from each model on a single page or via a single controller method.

My intuition is that I've either got to build a model for 'cv' (though there will only ever be one) and build the appropriate hasMany/belongsTo associations into a 'cv' and the content models respectively, or else to build a static page that is capable of making requests of model controllers individually. The former seems unnecessarily work-intensive given how small the project is, but in the latter case I don't know how to make requests of controllers to provide model data to a page. I'm sure this is dead simple, I just can't find the answer! Thanks!

1
I think you're on the right track with building the correct model relationships. If it seems like too much trouble for the project, well... to be honest, using a database to maintain one CV does seem like swatting a fly with a Buick.eaj
Re: 'swatting a fly with a Buick' lololol Yes, correct. But he's old, and particular, and chair of the department, and it's the easiest way for me to build something that a luddite can use and never mess up!Jonline

1 Answers

2
votes

You can make a DashboardsController (or whatever you want to call it), then in the Dashboard model, you specify that you don't need a database table: var $useTable = false;

In the Config/routes.php file, add: Router::connect('/', array('controller' => 'dashboards', 'action' => 'index')); to make that your homepage (if you want to).

Then, in the Dashboard controller's index action, you can use $this->loadModel('Whatever');, and you're good to go to get data from that model: $myData = $this->Whatever->find('all');. You can load as many models as you'll need the data for.

TLDR / simplified:

1) Make Dashboard controller with 'index' action
2) Make Dashboard model and specify: var $useTable = false;
3) Set Route to use your Dashboard controller for homepage (or any other page: 
  `Router::connect('/', array('controller' => 'dashboards', 'action' => 'index'));`
4) Use $this->loadModel('Whatever'); to gain access to that model's methods