문제

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