web-dev-qa-db-fra.com

Erreur CodeIgniter HMVC object_to_array ()

HMVC: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads

Après le téléchargement de CI et la copie sur le HMVC, le message d'erreur suivant s'affiche:

Une exception non interceptée a été rencontrée

Erreur-type

Message: Appel à la méthode non définie MY_Loader :: _ ci_object_to_array ()

Nom de fichier: /Users/k1ut2/Sites/nine.dev/application/third_party/MX/Loader.php

Numéro de ligne: 300

Traçage:

Fichier: /Users/k1ut2/Sites/nine.dev/application/controllers/Welcome.php Ligne: 23 Fonction: voir

Fichier: /Users/k1ut2/Sites/nine.dev/index.php Ligne: 315 Fonction: Demandez une fois

22
whisky

Il suffit d'ajouter ceci ici car le lien fourni par Clasyk ne fonctionne pas actuellement ...

La version courte de ce fil se résume à ceci ...

Dans application/third_party/MX/Loader.php, vous pouvez effectuer les opérations suivantes ...

Sous public function view($view, $vars = array(), $return = FALSE) Recherchez ... (ligne 300)

return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));

Remplacez ceci par

if (method_exists($this, '_ci_object_to_array'))
{
        return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));
} else {
        return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
}

C'est le résultat d'un "petit" changement non documenté mis en œuvre par les développeurs de CI, ce qui est bien!

Il y a une demande de tir sur Wiredesignz en attente d'action pour qu'il le sache ... 

En attendant, vous pouvez implémenter le "diddle" ci-dessus et revenir au codage :)

83
TimBrownlaw

HMVC ne fonctionne pas avec 3.1.3 (version actuelle). Mais fonctionne avec toutes les versions jusqu'à 3.1.2. Je viens de tester cela moi-même à partir de 3.0.0.

3
whisky

J'ai la solution.Cela fonctionne pour moi . En ligne 300 de l’application/third_party/MX/Loader.php

Cette ligne génère une erreur avec CI 3.1.3

return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_object_to_array($vars), '_ci_return' => $return));

Remplacez par cette ligne.

return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => $this->_ci_prepare_view_vars($vars), '_ci_return' => $return));
}
2
zaman sandhu

Trouvé cet endroit Utilisez cet endroit dans application/core/MY_Loader.php

De là https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/pull-requests/17/fix-loaderphp-for-ci-313/diff#comment-30560940

<?php (defined('BASEPATH')) OR exit('No direct script access allowed');

/* load the MX_Loader class */
require APPPATH."third_party/MX/Loader.php";

class MY_Loader extends MX_Loader
{
    /** Load a module view **/
    public function view($view, $vars = array(), $return = FALSE)
    {
        list($path, $_view) = Modules::find($view, $this->_module, 'views/');

        if ($path != FALSE)
        {
            $this->_ci_view_paths = array($path => TRUE) + $this->_ci_view_paths;
            $view = $_view;
        }

        return $this->_ci_load(array('_ci_view' => $view, '_ci_vars' => ((method_exists($this,'_ci_object_to_array')) ? $this->_ci_object_to_array($vars) : $this->_ci_prepare_view_vars($vars)), '_ci_return' => $return));
    }
}
2
Mr. ED

Ajoutez ces lignes dans application/third_party/MX/Loader.php après la ligne 307, 

protected function _ci_object_to_array($object) 
	{
    return is_object($object) ? get_object_vars($object) : $object;
    }

Cependant, pour 3.1.3, HMVC ne fonctionne pas.

plus de chance.

1
Ganga