在 PyroCMS(基于 CI 的 CMS)中使用 dbforge 时出现问题
我已经使用 PyroCMS 和 CI 有一段时间了,并且非常喜欢它。
我正在扩展一个数据库模块,该模块将允许管理员用户管理数据库,而无需使用 phpMyAdmin 之类的东西。
然而,我唯一能做的就是浏览表的字段值(即“SELECT * FROM 'table_name'”)。
我想包含更多功能,但我似乎无法让 dbforge 正常工作。我知道它已加载,因为 dbforge 用于卸载模块。从中调用函数时我也没有收到错误。
这是控制器中我的代码的示例(dbforge 已经加载)。
public function drop($table_name)
{
$table_name = $this->uri->segment(4);
$this->dbforge->drop_table($table_name);
redirect('admin/database/tables');
}
假设该函数是从此 url 调用的:
.../admin/database/drop/table_name
它似乎可以工作...但它只是重定向到表概述。
我有什么遗漏的吗? [$this->dbforge->drop_table($table_name);] 不应该总是删除表(假设 $table_name 有效)吗?
编辑
作为解决方法,我能够使用:
public function drop($table_name)
{
$table_name = $this->uri->segment(4);
//$this->dbforge->drop_table($table_name);
$this->db->query("DROP TABLE ".$table_name);
redirect('admin/database/tables');
return TRUE;
}
我真的很想使用 DB forge,但是......
I have been using PyroCMS and CI for quite some time, and truly love it.
I am extending a DB module that will allow an admin user to manage a DB without having to use something like phpMyAdmin.
The only thing I have been able to get working however is Browsing a table's field values (i.e 'SELECT * FROM 'table_name').
I want to include more functions, but I can't seem to get dbforge to work properly. I know it is loaded because dbforge is used to uninstall modules. I also get no error when calling functions from it.
Here is an example of my code from the controller (dbforge has already been loaded).
public function drop($table_name)
{
$table_name = $this->uri->segment(4);
$this->dbforge->drop_table($table_name);
redirect('admin/database/tables');
}
Lets say the function gets called from this url:
.../admin/database/drop/table_name
It appears to work... but instead it just redirects to the tables overview.
Is there something I am missing? Shouldn't [$this->dbforge->drop_table($table_name);] always drop a table (given $table_name is valid)?
EDIT
As a work around, I was able to use:
public function drop($table_name)
{
$table_name = $this->uri->segment(4);
//$this->dbforge->drop_table($table_name);
$this->db->query("DROP TABLE ".$table_name);
redirect('admin/database/tables');
return TRUE;
}
I really would like to use DB forge, however...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我认为您可能对 PyroCMS 1.3.x 中的站点前缀感到有点困惑。
默认情况下,社区和专业版的所有安装都将 default_ 作为第一个站点中所有表的前缀。如果你有专业版,你可以添加新站点,站点引用将是whatever_而不是default_
这个前缀由dbforge占,所以当你想删除default_blog时,你只需删除:
/admin/database/drop/blog
另外,为什么您是否接受 $table_name 作为参数,然后用 uri 段覆盖它?
另外,为什么您接受 $table_name 作为参数,然后用 uri 段覆盖它?
看看我在那里做了什么? xD
I think you might be getting a little confused by the site prefixes in PyroCMS 1.3.x.
By default all installations of Community and Professional will have default_ as a prefix for all tables in the first site. If you have Professional you can add new sites and the site reference will be whatever_ instead of default_
This prefix is accounted for by dbforge, so when you want to delete default_blog you would just delete:
/admin/database/drop/blog
Also, why are you accepting the $table_name as an argument then overriding it with a uri segment?
Also, why are you accepting the $table_name as an argument then overriding it with a uri segment?
See what I did there? xD