Welcome Guest, Not a member yet? Register   Sign In
How to call Model (used HMVC)
#1

[eluser]Ngua Go[/eluser]
i use HMVC but when call a model so error:

A PHP Error was encountered
Severity: Notice
Message: Undefined property: Index::$modeltest
Filename: backend/index.php
Line Number: 22

Model file: models/modeltest.php
I have tried to models of module: modules/news/models/modeltest.php
but still error occurs
the file modeltest.php is called but class Modeltest is not
#2

[eluser]d0ri0[/eluser]
I also get that error. It loads the model but I cannot use it.

A PHP Error was encountered

Severity: Notice

Message: Undefined property: Map::$module_model

Filename: controllers/map.php

Line Number: 34

Fatal error: Call to a member function get_settings() on a non-object in C:\wamp\www\cms\application\modules\map\controllers\map.php on line 34
#3

[eluser]Phil Sturgeon[/eluser]
Paste some code guys.
#4

[eluser]d0ri0[/eluser]
Code:
class Map extends Controller {

    function Map()
    {
        parent::Controller();  
        $this->load->model('module_model');
    }

    
    function display()
    {        
        $data['module'] = $this->module_model->get_settings(1);  

        $this->load->view('display', $data);
    }
    
}

It is the line $data['module'] = $this->module_model->get_settings(1); that produces the error.

I have also tried extending MX_Controller {} but that gives the error:
Code:
Fatal error: Call to undefined method MX_Controller::Controller() in C:\wamp\www\cms\application\modules\map\controllers\map.php

I swiched back to an older version of hmvc, that works good.
#5

[eluser]Phil Sturgeon[/eluser]
Code:
class Map extends MX_Controller {

    function Map()
    {
        parent::MX_Controller();  
        $this->load->model('module/model');
    }
#6

[eluser]d0ri0[/eluser]
I got : Fatal error: Call to undefined method MX_Controller::MX_Controller() in C:\wamp\www\cms\application\modules\map\controllers\map.php

But when removing the line parent::MX_Controller(); it worked. And the model could be used.

So, thanks for helping!
#7

[eluser]Ngua Go[/eluser]
thanks so much !
#8

[eluser]wiredesignz[/eluser]
Modular Extensions - HMVC version 5.3 is PHP5 only. So use __construct() instead.
#9

[eluser]d0ri0[/eluser]
Yes ofc. Thanks alot!
#10

[eluser]wortell[/eluser]
[quote author="d0ri0" date="1284668886"]I got : Fatal error: Call to undefined method MX_Controller::MX_Controller() in C:\wamp\www\cms\application\modules\map\controllers\map.php

But when removing the line parent::MX_Controller(); it worked. And the model could be used.

So, thanks for helping![/quote]


*bump!* pls?
me too, same issue...

CI 2.0, HMVC 5.3+, PHP 5.3+

my test...

/modules/welcome/

Code:
class Welcome extends Controller {

    function Welcome() {
       parent::Controller();
       $this->load->model("welcome_model");

       // ** DOES NOT! ** print out 'help!' accordingly
       print_r($this->welcome_model->get_greetee());

       $this->output->cache(CACHE_LIMIT);
    }

    function index() {
        echo "retrieved: ".$this->welcome_model->get_greetee();
        $this->load->view('welcome_message');
    }
}

Code:
class Welcome_model extends CI_Model {


    function welcome_model(){
        // Call the Model constructor
        parent::CI_Model();

        // prints out 'help!' accordingly
       echo $this->get_greetee();
    }

    function get_greetee(){
        echo "help!<br>";
    }

}




Theme © iAndrew 2016 - Forum software by © MyBB