Welcome Guest, Not a member yet? Register   Sign In
Turning MCV into MVCL: the solution to a mega project?
#4

[eluser]bretticus[/eluser]
You can really do whatever works best for you. There are no rules per say, just best practices. That being said...

You should really let the controllers do what they were meant to do. That is separate your models from your views (or your business logic from your layout.) Your business logic (or model) should know nothing about your layout, and your layout (views) should know nothing about your business logic.

Quote:Controller<---Get data from Model (does not have to be database data...remember...business logic)
Controller--&gt;Send data from model to the view.
That's it! You can have very "thin" controllers. This is advisable under most circumstances even (makes your site that much more modular and that's a good thing.)

As for the versioning, it seems it would be VERY trivial to extend your Loader class to look at configuration variables (could be as simple as an associative array that maps URL segments to version folders.)

This way, the versioning is transparent to your Controllers (as it should be.) Just make sure that your views are the same (if not possible than you can further extend the Loader class to get view files from a different folder.)

For example, here is an extended Loader class that I wrote to get views from alternate folders.

Code:
&lt;?php
class MY_Loader extends CI_Loader
{
    /**
     * Load View
     *
     *
     * @access    public
     * @param    string
     * @param    array
     * @param    bool
     * @return    void
     */
    function view($view, $vars = array(), $return = FALSE)
    {
            return $this->_ci_load(array('_ci_view' => $this->_get_prefix() . $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
    }

        function _get_prefix()
        {
            // config should load before Loader since Loader is called form the controller.
            $CI =& get_instance();
            if ( $CI->config->item('mobile_base_url') !== FALSE && $CI->config->_get_host_header() == $CI->config->item('mobile_base_url') ) {
                return ( $CI->config->item('mobile_view_folder') !== FALSE ) ? $CI->config->slash_item('mobile_view_folder') : '';
            } else {
                return ( $CI->config->item('base_view_folder') !== FALSE ) ? $CI->config->slash_item('base_view_folder') : '';
            }
        }
}
?&gt;

EDIT: I suppose I should show my extended Config lib too:

Code:
&lt;?php
class MY_Config extends CI_Config {

        // --------------------------------------------------------------------

    /**
     * Site URL
     *
     * @access    public
     * @param    string    the URI string
     * @return    string
     */
    function site_url($uri = '')
    {
                   if (is_array($uri))
        {
            $uri = implode('/', $uri);
        }

        if ($uri == '')
        {
            return $this->_get_host_header().$this->item('index_page');
        }
        else
        {
            $suffix = ($this->item('url_suffix') == FALSE) ? '' : $this->item('url_suffix');
            return $this->_get_host_header().$this->slash_item('index_page').preg_replace("|^/*(.+?)/*$|", "\\1", $uri).$suffix;
        }
    }

        /**
        * return URL for mobile base url if defined and matches hot header. otherwise, get base url.
        * @access       public
        * @return       string
        */

        function _get_host_header()
        {
            if ( $this->item('mobile_base_url') !== FALSE && strpos($this->item('mobile_base_url'), 'http://' . $_SERVER['HTTP_HOST']) !== FALSE ) {
                return $this->slash_item('mobile_base_url');
            } else {
                return $this->slash_item('base_url');
            }
        }

}


Messages In This Thread
Turning MCV into MVCL: the solution to a mega project? - by El Forum - 04-14-2010, 12:02 PM
Turning MCV into MVCL: the solution to a mega project? - by El Forum - 04-14-2010, 12:22 PM
Turning MCV into MVCL: the solution to a mega project? - by El Forum - 04-14-2010, 01:29 PM
Turning MCV into MVCL: the solution to a mega project? - by El Forum - 04-14-2010, 01:54 PM
Turning MCV into MVCL: the solution to a mega project? - by El Forum - 04-15-2010, 02:34 AM



Theme © iAndrew 2016 - Forum software by © MyBB