Welcome Guest, Not a member yet? Register   Sign In
ActiveRecord for CodeIgniter: Rails-style model interactions
#26

[eluser]sophistry[/eluser]
yes, trying this out on PHP4 i was able to get the basic find function-ality working! nice.

but, method chaining is not supported in PHP4 so i changed some code in the find function:
Code:
//line 261 from this:
$query = $this->db->where('id', $args)->from($this->_table)->get();

// to this:
$this->db->from($this->_table);
$this->db->where('id', $args);
$query = $this->db->get();

EDIT... this next code change is not right. something else was going wrong... read on.
and i changed the foreach loop at line 266 - I'm not sure this is completely right, but it stopped errors and i got the data from the find request:
Code:
// this:
foreach($this->_columns as $column)
     {
        eval('$return->' . $column->Field . ' = $found->' . $column->Field . ';');
     }

// EDIT... this is not right.
// becomes this:
$q = $this->_columns;
foreach($q->result() as $column)
     {
        eval('$return->' . $column->Field . ' = $found->' . $column->Field . ';');
     }

finally, i had to put a class var named for the model that is instantiated when extending the Controller class:

Code:
<?php

class Addresses extends Controller {

    var $Address;
    
    function Addresses()
    {
        parent::Controller();
        $Address =& $this->load->model('Address');
    }
    
    function index()
    {
        echo "Welcome to my address list!";
        
    }
    
    function viewer($id)
    {
        $the_address = $this->Address->find($id);
        print_r($the_address->host_domain);
    }
}
?>

oh yeah, two more things.
there is a syntax error in the latest download 032 on line 86:
Code:
$columns = $this->db->query('SHOW COLUMNS FROM ' . $this->_table)->result();
and in the wiki the example says to use view() as a controller method but i've found that using any reserved words is a recipe for strange errors and blank pages. better to use something like lookit or see or peruse.

anyhow, i look forward to exploring the full power of this contribution!
thanks.


Messages In This Thread
ActiveRecord for CodeIgniter: Rails-style model interactions - by El Forum - 09-24-2007, 01:19 PM



Theme © iAndrew 2016 - Forum software by © MyBB