• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
[Modular Extension] Model bug

#1
[eluser]grisha[/eluser]
I've tested this on a clean CI 1.7.1

Controller:
application/modules/welcome/controllers/welcome.php

Code:
<?php
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->model('TestModel');
        $this->load->view('welcome_message');
        $this->TestModel->A();
    }
}

/* End of file welcome.php */
/* Location: ./system/application/modules/welcome/controllers/welcome.php */

And the model:

Code:
<?php
class TestModel extends Model {

    function TestModel()
    {
        parent::Model();    
    }
    
    function A()
    {
        echo "Bark";
    }
}

/* End of file TestModel.php */
/* Location: ./system/application/models/TestModel.php */
?>

Error:

Code:
A PHP Error was encountered

Severity: Notice

Message: Undefined property: CI::$TestModel

Filename: libraries/Controller.php

Line Number: 95

It doesn't matter if the model is in
./system/application/models/TestModel.php
or
./system/application/modules/welcome/models/TestModel.php

When I print_r($this) after loading the view all I get is:
Code:
Welcome Object ( [_module:protected] => welcome [_ci_cached_vars] => Array ( ) [_ci_classes] => Array ( ) [load] => Welcome Object *RECURSION* )

Version tested: 5205, 5206

If I'm wrong with something - sorry and please give me an advice, what to do.

#2
[eluser]n0xie[/eluser]
Not a bug, it's a feature Wink

From the userguide:
Quote:Where Model_name is the name of your class. Class names must have the first letter capitalized with the rest of the name lowercase. Make sure your class extends the base Model class.

#3
[eluser]grisha[/eluser]
I know it is like that. I've changed it from 'TestModel', to 'Test_model', and the result of running the code, is just the same except the model class name in the error shown previously.

Controller:
Code:
<?php
class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $this->load->model('Test_model');
        print_r($this);
        $this->load->view('welcome_message');
        $this->Test_model->A();
    }
}
?>

Model:
Code:
<?php
class Test_model extends Model {

    function Test_model()
    {
        parent::Model();    
    }
    
    function A()
    {
        echo "Bark";
    }
}
?>

When I come back to the typical architecture (that means using app/controllers and app/models without the Modular Extension Libraries) everything works just Fine, and from the

Code:
print_r($this)
I get a massive array containing all the data as usual, whih is extreamly different from that one I've included in the first post.

Here is the code that I'm talking about. Check it if you can:
http://grisha.boo.pl/clean.zip

It contains a set up CI 1.7.1 in a folder called 'clean', so just extract it in your document root.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.