Paginate 在 Cakephp 中动态创建表?
请查看示例代码
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();
HOW?
*/
mysql_query('TRUNCATE table '.$tableName);
mysql_query('COMMIT;');
我想对创建的新表进行分页? 逻辑是每次有人运行脚本时都会创建一个新的随机命名表 ->然后分页->然后删除...或者我如何将模型分配给 cakePHP 中动态创建的表。
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();
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
听起来你所做的事情很糟糕。除此之外,您不应该调用 CREATE TABLE、TRUNCATE、COMMIT 等命令。
查看 sest 套件以了解如何正确创建和删除表,阅读 api 以了解如何执行事务。类似 http://api13.cakephp.org/class/data-source#method -DataSourcebegin
另外,表名应该是复数,以便 cake 能够自动执行此操作,因此您的示例将不起作用。
您可以通过执行以下操作来获取模型的实例
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