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.

有帮助吗?

解决方案

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

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top