RedBean ORM和Codeigniter,如何使Fuse识别从CI默认模型路径加载的模型? [英] RedBean ORM and Codeigniter, how to make Fuse recognize models loaded from CI default models path?

查看:151
本文介绍了RedBean ORM和Codeigniter,如何使Fuse识别从CI默认模型路径加载的模型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Codeigniter有自己的Models路径,其中模型从CI_Model延伸。我使用RedBean在Codeigniter中有一个库,将其加载到控制器上。加载Rb之后,我尝试使用CI Loader加载一个扩展了redbean_simplemodel的模型(wish工作,没有错误),但是当在bean上调用时,模型中的事件/方法没有效果。



例如,
APPPATH / application / libraries / rb.php

  class Rb {

function __construct()
{
//包含数据库配置
include(APPPATH。'/ config / database.php');

//获取Redbean
include(APPPATH。'/ third_party / rb / rb.php');

//数据库数据
$ host = $ db [$ active_group] ['hostname'];
$ user = $ db [$ active_group] ['username'];
$ pass = $ db [$ active_group] ['password'];
$ db = $ db [$ active_group] ['database'];

//设置DB连接
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 ,不等于«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?



感谢您的查找!



----- FOUND SOLUTION! $ b

其实,它的工作!我试图将代码放在我的模型下,方法store()。那不会工作!我试着放置一个名为update()的新方法,它的确工作!请检查下面的示例:

 类Model_song扩展RedBean_SimpleModel {

public function update(){
if($ this-> title!='test'){
throw new Exception(Illegal title!
}
}

}

如下:



假设您已经在Codeigniter上安装了RedBean



库$«
2)使用ci_loader,加载所需的模型(模型必须扩展redbean_simplemodel)



感谢您的查找!

解决方案

解决方案如下:



假设您已在Codeigniter上安装了RedBean


  1. 加载«redbean»库

  2. 使用ci_loader加载所需的模型(模型必须扩展为redbean_simplemodel)


Codeigniter has its own Models path, where models extend from CI_Model. I'm using RedBean has a library in Codeigniter, loading it on a controller. After loading Rb, I try to use CI Loader to load a model that extends redbean_simplemodel (wish works, there's no error), but the events / methods inside the model have no effect when they're called on bean.

For example, 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

And then on 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»!");
  }
 }

}

while on 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;

    }
}

My question is, how to make RedBean (FUSE http://redbeanphp.com/#/Fuse) work on Codeigniter ?

Thanks for looking!

----- FOUND SOLUTION!

Actually, it's working! I was trying to place code under my model, method store(). That wont work! I tryed to place a new method called update() and it does work! Check the example below:

class Model_song extends RedBean_SimpleModel {

 public function update() {
  if ( $this->title != 'test' ) {
    throw new Exception("Illegal title!");
  }
 }

}

The solution is the following:

"Assuming that you've already installed RedBean on Codeigniter"

1) Load the library for «redbean» 2) Using ci_loader, load the desired model (the model must extend redbean_simplemodel)

Thanks for looking! I hope this helps other people too.

解决方案

The solution is the following:

"Assuming that you've already installed RedBean on Codeigniter"

  1. Load the library for «redbean»
  2. Using ci_loader, load the desired model (the model must extend redbean_simplemodel)

这篇关于RedBean ORM和Codeigniter,如何使Fuse识别从CI默认模型路径加载的模型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆