Welcome Guest, Not a member yet? Register   Sign In
undefined function when using HMVC with CI 2.1.2
#1

[eluser]iansane[/eluser]
Hi,

I thought at first this was a issue with hmvc and sparks because with the basic php-activerecord test running vardump(Test::all()) I would get error message
"undefined function Test::all() when using hmvc.

But with further testing (fresh install of CI 2.1.2 it seems the problem is in loading any model when using hmvc.

I have this structure
application
-------modules
-------------test
----------------controllers
----------------------test.php
----------------models
----------------------Test.php

And here's my code.
controllers/test.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class test extends CI_Controller {

public function __construct()
{
  parent::__construct();
}

public function index()
{
  
  $this->load->model('test/test');
  
  echo Test::hello();

}
}

models/Test.php
Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Test{

    public function hello()
    {
     return "hello";
    }

}

And here is the stacktrace from xdebug:
Code:
( ! ) Fatal error: Call to undefined method test::hello() in E:\sandbox\ciblog\application\modules\test\controllers\test.php on line 15
Call Stack
# Time Memory Function Location
1 0.0004 337312 {main}( ) ..\index.php:0
2 0.0006 338224 require_once( 'E:\sandbox\ciblog\system\core\CodeIgniter.php' ) ..\index.php:202
3 0.0058 603176 call_user_func_array ( ) ..\CodeIgniter.php:359
4 0.0058 603224 test->index( ) ..\CodeIgniter.php:359

Anyone see what I"m doing wrong here or is there something changed in the new version of CI?

Thanks
#2

[eluser]emateu[/eluser]
You should extend MX_Controller and Test with uppercase in the first letter:

Quote:class test extends CI_Controller {

Code:
class Test extends MX_Controller {
#3

[eluser]emateu[/eluser]
And the model should be named test_model.php and inside:

Code:
class Test_Model extends CI_Model {
#4

[eluser]iansane[/eluser]
It's the Test_Model part that did it. It works whether MX_Controller or CI_Controller is extended since it's a simple controller.

But this causes problems for trying to integrate php-activerecord because the model name needs to be "Test" or else it is trying to find a table in the database called "Test_Model" which of course doesn't work.

I spent the day yesterday trying with the php-activerecord spark and getting the same error but if this is what has to be done to fix it then I don't see how it can work with php-activerecord.

I had this working once a year or two ago but don't remember how.

Thanks
#5

[eluser]iansane[/eluser]
[quote author="emateu" date="1344891657"]And the model should be named test_model.php and inside:

Code:
class Test_Model extends CI_Model {
[/quote]


I think I have it working fine now and don't have to name my model Whaterver_Model

I started using $ar = $this->load->model('test/test'); and it wouldn't work but then when I changed the module to welcome so I could do $ar = $this->load->model('welcome/test'); it works. So I think something about the module and the model both being named 'test' was causing the loader to bug out and not load the class but at the same time not throw a error of any kind.

I'll be sure to post back here if anything else comes up but right now I'm using php-activerecord and getting records from the db so I think it's all good.

Thanks
#6

[eluser]rei[/eluser]
[quote author="iansane" date="1344909272"][quote author="emateu" date="1344891657"]And the model should be named test_model.php and inside:

Code:
class Test_Model extends CI_Model {
[/quote]


I think I have it working fine now and don't have to name my model Whaterver_Model

I started using $ar = $this->load->model('test/test'); and it wouldn't work but then when I changed the module to welcome so I could do $ar = $this->load->model('welcome/test'); it works. So I think something about the module and the model both being named 'test' was causing the loader to bug out and not load the class but at the same time not throw a error of any kind.

I'll be sure to post back here if anything else comes up but right now I'm using php-activerecord and getting records from the db so I think it's all good.

Thanks[/quote]

Any updates on this one? I also want to use CI+PHPAR+HMVC. Any further issues in using it?




Theme © iAndrew 2016 - Forum software by © MyBB