找不到模块视图

时间:2015-11-19 14:51:42

标签: php codeigniter hmvc codeigniter-3 codeigniter-hmvc

我在使用带有模块的Codeigniter的HMVC实现时遇到了问题。

我创建了一个名为 autenticacion 的身份验证模块,由于显而易见的原因,为了检查会话的有效性和到期时间,总是在 MX_Controller 中使用,这种方式:

Modules::run('autenticacion/logout', $user, true);

Modules::run('autenticacion/update', $user);

取决于某些条件。

自从我添加了这个身份验证实现以来,对其他模块的正常访问被破坏了。

现在,如果我尝试访问

www.domain.com/items

我编写了这个模块文件:

modules/items/controllers/Items.php(这扩展了MX_Controller) 和观点:

modules/items/views/items_view.php

尽管视图已在Items控件中加载,但仍无法找到该视图。

如果我在Items构造函数中打印$ this, MY_Loader 实例将显示此属性:

[_ module:protected] => autenticacion

我理解这意味着 items 模块没有加载到加载器中,尽管我可以访问它的控制器。另一个模块( autenticacion )似乎搞得一团糟。

我该如何解决这个问题?

修改

这是我在 MX_Controller 中更改的内容,以便处理会话检查和更新:

<?

class MX_Controller 
{
    public $autoload = array();

    public function __construct() 
    {       
        // Validación de la autenticación/caducidad de la sesión
        $this->_validar_sesion();   

        // Original actions
        //....
    }


    //... method __get()


    /**
     * Checks whether the user has not yet created a valid authenticated user session, or if it has expired.
     * In both cases, it redirects to the authentication page, deleting the expired session if it was already created.
     */
    private function _validar_sesion()
    {
        if (stristr(get_class($this), 'autenticacion')) return; 

        require_once APPPATH . 'third_party/usuarios/Usuario.php';
        $this->load->model('autenticacion/autenticacion_model');

        // Get user instance from session
        $usuario = unserialize($this->session->userdata('usuario'));

        // No authenticated session yet: redirecting to the authentication page
        if (!stristr(current_url(), 'autenticacion') && ! $this->session->logged_in) {

            $this->load->library('uri');
            $uri = $this->uri->uri_string();

            redirect(base_url() . 'autenticacion' . ($uri ? '?redirect=' . $uri : ''));
        }

        // There is already an authenticated session, and the request is not coming from the authentication page
        elseif (!stristr(current_url(), 'autenticacion')) {

            // Check session expiration, in which case, we do logout
            if ($this->autenticacion_model->sesion_caducada($usuario, config_item('sess_companyname_expiration'))) {

                // This will delete the session from DB, destroy it, and redirect to the authentication page
                Modules::run('autenticacion/logout', $usuario, true);

            }
            // Session has not expired yet: we update the session timestamp in DB to extend the expiration time
            else {

                Modules::run('autenticacion/update', $usuario);

            }           

        }

    }
}

0 个答案:

没有答案
相关问题