Welcome Guest, Not a member yet? Register   Sign In
Modular Extensions - HMVC version 5.3

[eluser]jatin.soni[/eluser]
Hello,

I am having trouble in loading model from sub modules. Here is some details.

I am having few modules and sub-modules as below
Code:
modules/admin/
modules/admin/models
modules/admin/controllers
modules/admin/views

modules/admin/models/dashboard/
modules/admin/controllers/dashboard/
modules/admin/views/dashboard/

modules/admin/models/plugs/
modules/admin/controllers/plugs/
modules/admin/views/plugs/

Each M/V/C has own files in it.

Now I have created model in modules/admin/models/plugs/ just for testing purpose something like below

Plugs Model
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Plugs extends CI_Model
{
    public function __construct()
    {
        parent::__construct();    

    }


    public function mymeta()
    {
        return 'plugs model loded';
    }

}

And now trying to load into Plugs Controller as below

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

class Plugs extends MX_Controller
{
    public function __construct()
    {
        parent::__construct();

        $this->load->model('plugs');
    }

    public function index()
    {
        $this->load->view('plugs/index');
    }

    public function get_plugin_meta()
    {
        echo $this->plugs->mymeta(); // this is the method from Plugs Models
    }  

}
But when I tried to access the URL http://localhost/mysite/admin/plugs or http://localhost/mysite/admin/plugs it is giving me below error.

Quote:An Error Was Encountered

Unable to locate the model you have specified: plugs

So than how to load model in controller?

[eluser]XMadMax[/eluser]
Hi jatin,

I think the problem is a duplicate name in the loader, remember ever to have unique names for controllers and models:

Rename Plugs (model) to Plugs_model, also rename the file as plugs_model.php

Hope it helps,

Xavier

[eluser]InsiteFX[/eluser]
Make sure you specifiy your module paths in the config.php file like below.
Code:
$config['modules_locations'] = array(
    APPPATH.'modules/' => '../modules/',
);

[eluser]redcloud80[/eluser]
Hi! I'm trying to use HMVC with my CI project but I'm stuck with path problems (I suppose!).

This is my current application tree

Code:
- application
--- controllers
------ subcontrollers
--------- first_controller.php (which extends MY_Controller)
--------- secnd_controller.php (which extends Better_Controller)
|...
|...
--- core
------ MY_Controller.php

MY_Controller.php file contains two classes
Code:
class MY_Controller extends CI_Controller
...
...
class Better_Controller extends MY_Controller

and works when I try to reach domain.com/subcontrollers/first_controller


Now I'd want to move all subcontrollers to modules for HMVC
Code:
- application
--- modules
------ subcontrollers
--------- first_controller
------------ controllers
--------------- first_controller.php
--------- secnd_controller
------------ controllers
--------------- secnd_controller.php

but when I try to hit domain.com/subcontrollers/first_controller I get a class not found error.
I tried to remove the subcontrollers dir level and force MY_Controller to extend MX_Controller instead of CI_Controller but both attempts were not working. Any suggestion?



EDIT: Removing the subcontrollers dir and forcing MY_Controller to extend CI_Controller seems to work. This is the app tree
Code:
- application
--- modules
------ first_controller
--------- controllers
------------ first_controller.php
------ secnd_controller
--------- controllers
------------ secnd_controller.php

but how can I solve preserving the subcontrollers dir?

[eluser]ivantcholakov[/eluser]
@redcloud80

I use a modification of HMVC, anyway this might work:

Code:
- application/
--- modules/
------ subcontrollers/ (this is the module name actually)
---------- controllers/
-------------- first_controller.php
-------------- second_controller.php
---------- views/

[eluser]redcloud80[/eluser]
[quote author="ivantcholakov" date="1410629625"]@redcloud80

I use a modification of HMVC, anyway this might work:

Code:
- application/
--- modules/
------ subcontrollers/ (this is the module name actually)
---------- controllers/
-------------- first_controller.php
-------------- second_controller.php
---------- views/
[/quote]

Thanks, it works perfectly but it's not a good solution for me Sad

[eluser]ivantcholakov[/eluser]
@redcloud80

Another way:

Your last solution is possible too, but within routes.php you should write rules that insert the additional subdirectory segment. It is possible, somehow I don't like this way.

[eluser]ivantcholakov[/eluser]
The third way:

Code:
- application/
--- modules/
------ subcontrollers/
---------- controllers/
-------------- first_controller/
------------------ first_controller.php
------------------ why_not_another_controller.php
-------------- second_controller/
------------------ second_controller.php
---------- views/

This is a possible implementation on my HMVC modification, you may check whether it works with the original one.

[eluser]redcloud80[/eluser]
[quote author="ivantcholakov" date="1410631479"]The third way:

Code:
- application/
--- modules/
------ subcontrollers/
---------- controllers/
-------------- first_controller/
------------------ first_controller.php
------------------ why_not_another_controller.php
-------------- second_controller/
------------------ second_controller.php
---------- views/

This is a possible implementation on my HMVC modification, you may check whether it works with the original one.[/quote]
This could work too but, unfortunately, I've just a single controller file for each controller... adding just another folder it's not a solution. Nice one though Wink
Maybe I'll go for the routes mapping solution.

[eluser]ivantcholakov[/eluser]
The radically new feature in the third way is "why_not_another_controller.php". It is not about a single controller within a single folder. Anyway, I am glad that you can figure out how to get to your solution.




Theme © iAndrew 2016 - Forum software by © MyBB