【发布时间】:2011-09-21 09:57:35
【问题描述】:
Codeigniter 有自己的模型路径,其中模型从 CI_Model 扩展而来。我正在使用 RedBean 在 Codeigniter 中有一个库,将其加载到控制器上。加载Rb后,我尝试使用CI Loader加载一个扩展redbean_simplemodel的模型(wish可以,没有错误),但是模型内部的事件/方法在bean上调用时没有任何作用。
例如, APPPATH/application/libraries/rb.php
class Rb {
function __construct()
{
// Include database configuration
include(APPPATH.'/config/database.php');
// Get Redbean
include(APPPATH.'/third_party/rb/rb.php');
// Database data
$host = $db[$active_group]['hostname'];
$user = $db[$active_group]['username'];
$pass = $db[$active_group]['password'];
$db = $db[$active_group]['database'];
// Setup DB connection
R::setup("mysql:host=$host;dbname=$db", $user, $pass);
} //end __contruct()
} //end Rb
然后继续 APPPATH/application/models/model_song.php
class Model_song extends RedBean_SimpleModel {
public function store() {
if ( $this->title != 'test' ) {
throw new Exception("Illegal title, not equal «test»!");
}
}
}
开启时 APPPATH/application/controllers/welcome.php
class Welcome extends CI_Controller {
public function index()
{
$this->load->library('rb');
$this->load->model('model_song');
$song = R::dispense('song');
$song->title = 'bluuuh';
$song->track = 4;
$id = R::store($song);
echo $id;
}
}
我的问题是,如何让 RedBean (FUSE http://redbeanphp.com/#/Fuse) 在 Codeigniter 上工作?
感谢收看!
-----找到解决方案!
实际上,它正在工作!我试图将代码放在我的模型下,方法 store()。那是行不通的!我尝试放置一个名为 update() 的新方法,它确实有效!检查以下示例:
class Model_song extends RedBean_SimpleModel {
public function update() {
if ( $this->title != 'test' ) {
throw new Exception("Illegal title!");
}
}
}
解决方法如下:
“假设你已经在 Codeigniter 上安装了 RedBean”
1) 加载 «redbean» 的库 2)使用ci_loader,加载需要的模型(模型必须扩展redbean_simplemodel)
感谢收看!我希望这对其他人也有帮助。
【问题讨论】:
标签: codeigniter orm