开发者

Paginate Dynamically created table in Cakephp?

开发者 https://www.devze.com 2023-02-06 00:23 出处:网络
Please look at the sample code mysql_query(\'SET AUTOCOMMIT=0;\'); mysql_query(\'START TRANSACTION;\');

Please look at the sample code

            mysql_query('SET AUTOCOMMIT=0;');
            mysql_query('START TRANSACTION;');
            $tableName = rand().'_table;'
            $this->loadModel('Home'); // Model for homes_table

            $sql = 'CREATE TABLE '.$tableName.'_table LIKE homes_table';
            mysql_query($sql);
            // FEW INSERT STATEMENTS ON THE NEW TABLE $tableName //
            /*

            Here I want to paginate the new table
            using $this->paginate(); 
        开发者_C百科    HOW?

            */

        mysql_query('TRUNCATE table '.$tableName);
        mysql_query('COMMIT;');

I want to paginate the new table created? Logic is each time a person runs the script a new random named table will be created -> then paginated -> then droped ... Or how do I assign Model to dynamically created tables in cakePHP.


its sounds like what you are doing is bad. Besides that you should not be calling things like CREATE TABLE, TRUNCATE, COMMIT etc.

Look at the sest suite for how to properly create and delete tables, read the api on how to do transactions. things like http://api13.cakephp.org/class/data-source#method-DataSourcebegin

also the table name should be plural for cake to be able to do this auto, so your example would not work.

You can get a instance of the model by doing

$Something = ClassRegistry::init(Inflector::classify($tableName . '_suffix'));
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号