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

[eluser]Maurice Calhoun[/eluser]
Php 4 ready, just change the constructor and the __call method

Code:
/**
     * Constructor
     *
     * @access public
     */
    function ActiveRecord()
    {
        parent::Model();
        overload('ActiveRecord');
        log_message('debug', "ActiveRecord Class Initialized");
    }

    /**
     * __call
     *
     * Catch-all function to capture method requests for Active Record-style
     * functions and pass them off to private methods. If no function is
     * recognised, this acts as a getter/setter (depending on whether any
     * arguments were passed in).
     *
     * @access    public
     * @param    string
     * @param    array
     * @return    function || void
     */    
    function __call($method, $args, &$result)
    {
        if (stristr($method, 'find_by_')) $result = $this->_find_by(str_replace('find_by_', '', $method), $args);
        if (stristr($method, 'find_all_by_')) $result = $this->_find_all_by(str_replace('find_all_by_', '', $method), $args);
        if (stristr($method, 'fetch_related_')) $result  = $this->_fetch_related(str_replace('fetch_related_', '', $method), $args);
        if ( ! isset($args) ) eval('return $this->' . $method . ';');
        eval('$this->' . $method . ' = "' . $args[0] . '";');
        
        return $result;
        
    }


Messages In This Thread
ActiveRecord for CodeIgniter: Rails-style model interactions - by El Forum - 09-24-2007, 10:51 AM



Theme © iAndrew 2016 - Forum software by © MyBB