Welcome Guest, Not a member yet? Register   Sign In
Once the model is loaded by the controller all model methods are exposed to view
#4

I believe this bit of code is what controls loading up those models to be accessible in a view:

PHP Code:
// This allows anything loaded using $this->load (views, files, etc.)
// to become accessible from within the Controller and Model functions.

$_ci_CI =& get_instance();
foreach (
get_object_vars($_ci_CI) as $_ci_key => $_ci_var)
{
    if ( ! isset(
$this->$_ci_key))
    {
        
$this->$_ci_key =& $_ci_CI->$_ci_key;
    }


It is found in system/ci/core/loader.php protected function _ci_load, at least in my version of CI.

Since it is used by several loaders you would want to include another variable flag in the calling function: 
PHP Code:
public function view($view$vars = array(), $return FALSE)
{
    return 
$this->_ci_load(array('_ci_view' => $view'_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return), $MY_NEW_BOOL_FLAG);
    
//You could also add '_ci_prevent_model_load' => true to the data package and check for that in _ci_load, that's cleaner and follows their convention


Add that flag to the _ci_load() function, and then when it's true you could probably do something like check if(is_subclass_of($_ci_CI->$_ci_key, 'CI_Model')) then don't load it.

The function opens with:
PHP Code:
// Set the default data variables
foreach (array('_ci_view''_ci_vars''_ci_path''_ci_return') as $_ci_val)
{
    $
$_ci_val = ( ! isset($_ci_data[$_ci_val])) ? FALSE $_ci_data[$_ci_val];

so it seems like your $vars data would still be loaded up.

I haven't tried this, but if it doesn't work just like that I think it would put you on the path to getting things to work as you like.
Reply


Messages In This Thread
RE: Once the model is loaded by the controller all model methods are exposed to view - by bmcn - 12-11-2018, 02:47 PM



Theme © iAndrew 2016 - Forum software by © MyBB