Question

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.

Was it helpful?

Solution

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

OTHER TIPS

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

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top