Welcome Guest, Not a member yet? Register   Sign In
HMVC not working fine
#1

[eluser]alikhan88[/eluser]


I am working on creating an application with having an HMVC structure in codeigniter and i also require API Centric application , so i used https://bitbucket.org/wiredesignz/codeig...sions-hmvc for HMVC and Rest_Controller of Phil Sturgeon, now everything is working fine , the url's the modular controllers are working fine

i have created views path like that
application/modules/modulename/views/mainview.php
application/modules/modulename/views/subdir/view.php
application/modules/modulename/views/subdir/view2.php


and trying to access it in
/application/modules/modulename/controller/controller.php

as

$this->load->view("subdir/view");

doesn't work

but this works

$this->load->view("mainview");

I created a copy of the directory "subdir" to
/application/views/

it started working, so it's basically taking path to the main application.

Kindly let me know , how can i resolve it

Problem # 2

for each controller in the module i have to add the static path

require APPPATH.'modules/modulename/libraries/REST_Controller.php';

i want to make this path dynamic , or auto load libraries for each module in the module's library folder, adding library name in the module/config/autoload.php is not working for me , as i think the reason is the code flow of application, first the application flow goes to the controller and it gets to my class extending the REST_Controller and gives the error , unable to load the REST_Controller Class

Note: if i put the Rest_Controller.php and Format.php in the application/libraries/ folder, everything works fine , but i want this to be modular , and make the module restful

how can i load libraries specifically from the module/libraries how to make it proper modular, so that there should be a complete instance of codeigniter in the module ,it should work freely, including the files loaded from the main application.

My folder structure is as follows

application
- - modules
- - - - modulename
- - - - - - controller
- - - - - - libraries
- - - - - - config
- - - - - - models
- - - - - - views

My Rest_Controller Class in the application/modules/module_name/libraries/Rest_Controller.php

abstract class REST_Controller extends MX_Controller

My Controller Class in application/modules/module_name/controllers/User.php

require APPPATH.'modules/modulename/libraries/REST_Controller.php';
class User extends REST_Controller
{

this works fine but if i remove the require line from the top , it doesn't work and even if i add the library name to autoload.php in the /modulename/config/autoload.php

it doesn't work My autoload.php /application/modules/modulename/config/autoload.php

<?phpif ( ! defined('BASEPATH')) exit('No direct script access allowed');
$autoload['packages'] = array();
$autoload['libraries'] = array('database', 'session','modulename/REST_Controller');
$autoload['helper'] = array('url', 'file');
$autoload['config'] = array();
$autoload['language'] = array();
$autoload['model'] = array();

and autoload.php in my application/config/autoload.php is empty, means no autoload mentioned

#2

[eluser]alikhan88[/eluser]
Anyone there , Please Reply
#3

[eluser]InsiteFX[/eluser]
Did you add the modules location information to the ./app/config/config.php file?

Code:
$config['modules_locations'] = array(
    APPPATH.'modules/' => '../modules/',
);
#4

[eluser]alikhan88[/eluser]
Yeah this I have added to the config file that's y the following is working

/application/modules/modulename/controller/controller.php

/application/modules/modulename/views/mainview.php

But view doesn't work here at the following location

/application/modules/modulename/views/sub/view2.php

Sub directories in the modules don't work, it tries to look for the subdirectories in the main application level , I made the subdir at the main views
/application/views/subdir/view2.php

And called it in this controller below
/application/modules/modulename/controller/controller.php
Like this
$this->load->view("subdir/view2.php")
And it worked
Removed the subdir from main application level stopped working , subdirectories are not working on modular level

Thanks
#5

[eluser]InsiteFX[/eluser]
If you are using CI 2.2 it will not work with that version, the last version that that branch worked on was CI 2.1.4
#6

[eluser]wiredesignz[/eluser]
There is nothing in the CI 2.2.0 version changelog to suggest that the current version of Modular Extensions - HMVC will not work.

Quote:If you are using CI 2.2 it will not work with that version ...

@InsiteFX, What specifically is not working that makes you post that comment.

#7

[eluser]alikhan88[/eluser]
I have downloaded the 2.1.4 version and installed everything on that , but still the same issues , i have echoed $this->load in the controller of module , pasting here , hope it helps to track the problem

MY_Loader Object
(
[_module:protected] => admin
[_ci_plugins] => Array
(
)

[_ci_cached_vars] => Array
(
)

[_ci_ob_level:protected] => 1
[_ci_view_paths:protected] => Array
(
[application/views/] => 1
)

[_ci_library_paths:protected] => Array
(
[0] => application/
[1] => /www/vts/system/
)

[_ci_model_paths:protected] => Array
(
[0] => application/modules/admin/
[1] => application/
)

[_ci_helper_paths:protected] => Array
(
[0] => application/
[1] => /www/vts/system/
)

[_base_classes:protected] => Array
(
[benchmark] => Benchmark
[hooks] => Hooks
[config] => Config
[utf8] => Utf8
[uri] => URI
[router] => Router
[output] => Output
[security] => Security
[input] => Input
[lang] => Lang
[loader] => Loader
[model] => Model
)

[_ci_classes:protected] => Array
(
[session] => session
)

[_ci_loaded_files:protected] => Array
(
[0] => /www/vts/system/libraries/Session.php
)

[_ci_models:protected] => Array
(
[0] => admin_model
)

[_ci_helpers:protected] => Array
(
[string_helper] => 1
[url_helper] => 1
[common_helper] => 1
)

[_ci_varmap:protected] => Array
(
[unit_test] => unit
[user_agent] => agent
)

[controller] => Admin Object
(
[autoload] => Array
(
)

[load] => MY_Loader Object
*RECURSION*
)

)

well i am not much into codeigniter, but in the array below, only model key is pointing to right location
[_ci_model_paths:protected] => Array
(
[0] => application/modules/admin/
[1] => application/
)

thanks
#8

[eluser]InsiteFX[/eluser]
I posted that because I have it working fine in CI 2.1.4 but it refuses to work with the same code in CI 2.2

That's why I have asked you several times that if you had time to take a look at it, they have been changing everything to protected methods.

I can list like 10 others that cannot get it to work also with CI 2.2
#9

[eluser]wiredesignz[/eluser]
@InsiteFX, Please be more specific about the problems you're having!

I have dropped CI 2.2.0 into 3 applications originally written to run on CI 2.0.3 using Modular Extensions - HMVC and they all still work correctly. (Apart from PDO driver issues)

So the problem you might be having could be due to CI 2.2.0 or your own code rather than Modular Extensions - HMVC.

As far as other people having difficulties, I haven't heard from anyone so how could I possibly know?

@alikhan88, Use the forum code tags if you want help, otherwise your code is too painful to read.
Your view problem is possibly due to the sub-directory name being the same as a module name.
if you're in doubt then try using the modulename/subdir/view format.

Code:
$this->load->view('modulename/subdir/view');

The other issue you're having with base classes located at module level will require you to use PHP includes. The autoload functionality built into Modular Extensions - HMVC only works for base classes located in the "application/core" and "application/libraries" directories.
#10

[eluser]InsiteFX[/eluser]
Hi Wiredesignz,

I stand corrected, I re-downloaded the CI 2.2.0 and now it is working, maybe the first download got corrupted which we all know happens from CI.

I just re-set everything up using the welcome and a MY_Controller and everything is working fine.

I should have re-downloaded the first time it did not work.

Sorry for my mistake.





Theme © iAndrew 2016 - Forum software by © MyBB