1

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.

1
  • 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. Commented Oct 4, 2013 at 10:52

2 Answers 2

5

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'); 
Sign up to request clarification or add additional context in comments.

1 Comment

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');
-1

You Can do it by firing normal mysql queries selecting table and fetching values in controller as we do in core php.

2 Comments

Yeah, I had done in that way. But feeling like, what's need of doing it in a framework?
Yes I know but i think this is the solution matching to your requirement.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.