Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - (HMVC) - Version 3.1.9
#31

[eluser]Adods[/eluser]
is this helper function is to call controller inside another controller or something like that?? so, i can use both matchbox and this helper, right?
#32

[eluser]Edemilson Lima[/eluser]
Yes, the modules are like controllers, they can load their own views and models, but they goes into the "modules" directories, separated from the real controllers.

In this version you may not need Matchbox, since you can put your views, models and also controllers into subdirectories under the modules directory.
#33

[eluser]Adods[/eluser]
I have problem when call a model from a module controller.

This is my Module Controller :
Code:
class Adminmenu extends Module {
    function Adminmenu() {
        parent::Module();
        $this->load->module->model('menu','adminmenu');
    }
    
    function Index() {
        $this->load->module->view('menu_view');
    }
}

this is my model:
Code:
class Menu extends Model {
    var $id;
    var $parent_id;
    var $backname;
    var $main;
    var $viewable;
    var $addable;
    var $editable;
    var $deletable;
    
    function Menu() {
        parent::Model();
    }
    
    function getViewableModules($main=1,$parent=0) {
        $this->db->where('back',1);
        $this->db->where('viewable',1);
        $this->db->where('main',$main);
        $this->db->where('parent',$parent);
        $result = $this->db->get('modules');
        return $result;
    }
}

and this is my view:
Code:
class Menu extends Model {
    var $id;
    var $parent_id;
    var $backname;
    var $main;
    var $viewable;
    var $addable;
    var $editable;
    var $deletable;
    
    function Menu() {
        parent::Model();
    }
    
    function getViewableModules($main=1,$parent=0) {
        $this->db->where('back',1);
        $this->db->where('viewable',1);
        $this->db->where('main',$main);
        $this->db->where('parent',$parent);
        $result = $this->db->get('modules');
        return $result;
    }
}

and return error : "Fatal error: Class 'Model' not found in C:\Xampp\xampp\htdocs\ci161\system\admin\blocks\adminmenu\models\menu.php on line 2"

is there something wrong??

EDIT:
i call that module on my controller view
#34

[eluser]wiredesignz[/eluser]
Well your View and your Model appear to have the same code... :lol:

Aside from that the error source looks strange. " \system\admin\blocks\adminmenu\models\menu.php on line 2 ” this doesn't make sense as far as a CI application

Where have you put your modules, they should be set like this:
Code:
application/
    - modules/
        - name_of_module/
            - controllers/

            - models/

            - views/
#35

[eluser]Adods[/eluser]
No. i have change the modules directory to 'blocks' and i put all script above inside adminmenu directory in blocks folder.

and my main controller is like this :
Code:
class Useradmin extends Controller {
    function __construct() {
        parent::Controller();
    }
    
    function Index() {
        $data['view']='Test Text';
        $this->load->view('main',$data);
    }
}

this is my main view
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;
&lt;title&gt;&lt;?=$this->config->item('page_title');?&gt;&lt;/title&gt;
&lt;link href="&lt;?=$this-&gt;config->item('base_url');?&gt;/css/suckerfish.css" rel="stylesheet" type="text/css" />
&lt;/head&gt;

&lt;body&gt;
<table width="100%" border="1" cellspacing="0" cellpadding="5" style="border-collapse:collapse;">
    <tr>
        <td><h1>&lt;?=$this->config->item('page_header');?&gt;</h1></td>
    </tr>
    <tr>
        <td>
        <div id="nav">
        &lt;?=modules::run('adminmenu');?&gt;
        </div>
        </td>
    </tr>
    <tr>
        <td>&lt;?=$view?&gt;</td>
    </tr>
</table>
&lt;/body&gt;
&lt;/html&gt;
#36

[eluser]wiredesignz[/eluser]
Well the error says the main CI_Model class cannot be found, have you altered any other Codeigniter file locations?

Try loading a Model inside Useradmin Controller see if that works.
#37

[eluser]Adods[/eluser]
No. I haven't. It's still fresh.

If I call model from main controller it works normally, but if I call model inside module controller the error appears. I have tried on new copy of CI but it's still error.

sorry if my english is bad. Big Grin
#38

[eluser]Adods[/eluser]
I've added some lines to your helper and it works :cheese:.

here are the changes I've made :
Code:
class Module
{
    function Module()
    {
        $this->_base = 'blocks/';
        $this->load =& new Loader($this);
        $this->load->_ci_assign_to_models();
        $this->_assign_libraries();
        log_message('debug', ucfirst(get_class($this))." module initialised");
    }
.
.
.

class Loader extends CI_Loader
{
    function Loader(&$_module)
    {
        parent::CI_Loader();
        $this->module  =& new Extended_Loader($_module, $this, $_module->_base);
        $this->_module =& $_module;
    }
.
.
.

class Extended_Loader
{
.
.
.
function view($view, $data = array(), $return = '')
    {
        $this->_load->_ci_view_path = APPPATH.$this->_base.get_class($this->_module).'/views/';
        return $this->_load->view($view, $data, $return);
    }
    
    function model($model, $alias = '', $connect = '')
    {
        if ( ! class_exists('Model'))
        {
            load_class('Model', FALSE);
        }
        
        if ($connect) $this->_load->database();
        
        $model = get_class($this->_module).'/'.$model;    
        
        if (!empty($alias))
        {
            $this->_module->$alias =& modules::load($model, 'models/');
        }
        else modules::load($model, 'models/');
        
        $this->_module->_assign_libraries();
    }
.
.
.

I hope you don't get mad because of it. Smile


the problem is, I can't call the function in my model when using model alias.
it says that 'getViewableModules' method doesn't exist, the function can only be called using main name.
i mean, this call doesn't work:
$this->modelalias->method()
but this one works:
$this->modelname->method()
#39

[eluser]wiredesignz[/eluser]
Yes... the modules->model loader does not load the CI_Model class.


I will fix this. please check the wiki soon. Wink
#40

[eluser]wiredesignz[/eluser]
You are welcome to change anything... if it is a good change I will include it. Wink




Theme © iAndrew 2016 - Forum software by © MyBB