My doubt is, I had few tables named client1,client2,client3 etc., I need to get the data of each client in single controller without creating any model/controller for each table. Can any one explain how to get those values.
- A model represents data, and a controller (usually) fetches that data. Now, why are you not wanting to use these? As otherwise, there’s no point in using an MVC framework like CakePHP if you’re not wanting to adhere to MVC principles.Martin Bean– Martin Bean2013-10-04 10:52:30 +00:00Commented Oct 4, 2013 at 10:52
Add a comment |
2 Answers
You can use dynamic models
app/client_model.php
<?php class ClientModel extends Model { var $name = 'Client'; var $alias = 'Client'; function __construct($table) { $this->useTable = $table; parent::__construct(); } } ?> And Use like this for client1 table
App::import('model','Client'); $client = new ClientModel('client1'); $client->find('all'); 1 Comment
Kluny
I ended up using this - I have an EmailForms controller/model and I needed and EmailFormSubmissions controller/model, and for various terrible reasons I could not write them as two separate model/controllers - I had only one model/controller available to do double duty. So I insantiate a new EmailForm like this: $emailFormSubmission = new EmailForm('email_form_submissions');
You Can do it by firing normal mysql queries selecting table and fetching values in controller as we do in core php.