CodeIgniter, models, and ORM, how to deal with this?

后端 未结 10 824
谎友^
谎友^ 2021-02-03 19:11

I\'m starting with CodeIgniter and after several hours diving in Google I\'m a bit confused.

Let\'s try to explain my question with a easy example: I have a table \'car

相关标签:
10条回答
  • 2021-02-03 19:48

    I used CodeIgniter with Propel and they really mixed well. I've used like that for a while and got a few webapps working that way. Since I found a few awful ways to do it ( some included modifiying Apache's configuration!!). I decided to publish a blog post on how to do it. You can read it here.

    Hope I can help!

    0 讨论(0)
  • 2021-02-03 19:48

    I think php-activerecord is a very good drop-in ORM. I've used it with the Slim Framework a few times and I think it would be a great alternative to using CI's native model class. Here is some sample code and the link:

    $post = new Post();
    $post->title = 'My first blog post!!';
    $post->author_id = 5;
    $post->save();
    

    PHP ActiveRecord

    0 讨论(0)
  • 2021-02-03 19:48

    i know this is quite old, but for those who are just using codeigniter now and wannt to use an orm with it can use this tutorial to integrate propel with codeigniter

    http://llanalewis.blogspot.com/2013/06/installing-propel-in-codeigniter.html

    0 讨论(0)
  • 2021-02-03 19:50

    take a look the the codeigniter wiki page for ORM

    http://codeigniter.com/wiki/ORM/

    0 讨论(0)
  • 2021-02-03 19:52

    For future Googlers, here is a tutorial I wrote up about how to integrate CodeIgniter 2 with Doctrine 2.

    Let me know if you have any issues.

    0 讨论(0)
  • 2021-02-03 19:53

    You probably want something like this:

       class Cars {
    
        //List all neccessary vars here
    
        function __construct() {
            //get instance of Codeigniter Object and load database library
            $this->obj =& get_instance();
            $this->obj->load->database();
        }
    
    //You can now list methods like so:
    function selectCar($name, $color) {
    
            $this->obj->db->select('color')->from('car')->where('color', $color);
            $query = $this->obj->db->get();
    
            switch ($query->num_rows()) {
            case 0:
                return false;
                break;
            default:
                return $query->result();
                break;
            }
        }
    

    Hope that helps!

    0 讨论(0)
提交回复
热议问题