Welcome Guest, Not a member yet? Register   Sign In
How to extend core classes when working with the HMVC Extension?
#1

[eluser]gunnarflax[/eluser]
Hi!

I've just discovered the HMVC extension which allows for modularity. But what I don't understand is how I can extend core classes while using it.

I have a module in the /application/modules/ directory which in turn have an extended core controller called "MY_Controller". But when I try to extend it through a controller I get the error message the class can not be found. Why is that? I can extend both CI_Controller and MX_Controller but why can't I extend with MY_Controller?
#2

[eluser]scottwire[/eluser]
I have a core class doing the same thing extending MX_Controller

/application/core/Site_Controller.php
class Site_Controller extends MX_Controller{

}

/application/modules/pages/controllers/pages.php
class Pages extends Site_Controller {

}


This works for me. Post your full class code if that doesn't help?
#3

[eluser]gunnarflax[/eluser]
This is a hypothetical directory structure for the project:

Code:
-- System
-- Application
---- controllers
---- views
---- models
---- modules
------ admin
-------- controllers
---------- Admin_Controller.php = extending MY_Controller
-------- views
-------- models
-------- core
---------- MY_Controller.php = extending MX_Controller
-------- modules

is this possible? I'm having some trouble planning my project since I don't fully understand how to utilize HMVC effectively.

Can I have modules within modules? They won't be accessed by the URL, they will only be providing modularity to the admin module - which in turn is a module used by the frontend.

Is this at all possible? I've looked at the source of PyroCMS and it looks like they are doing it about the same way.
#4

[eluser]scottwire[/eluser]
I don't believe you can do it this way. Your structure is how I originally wanted to set up a CMS I built but I think it would take a bit of restructuring the way HMVC works in order to do it this way. It made sense to me to split out an admin section and a site section and put modules under each, but unfortunately you can't do modules within modules as far as I know without altering HMVC. I've also never tried to use a core folder within a module. I'm not sure that will work either. I don't see PyroCMS doing it that way.

What PyroCMS does and what I ultimately did as well is to have an admin.php file in each module. This makes it more portable.

So if you have a blog module

modules
---blog
----controllers
-----admin.php
-----blog.php
---slideshow
----controllers
-----admin.php
-----slideshow.php

Then in config/routes.php
$route['admin/([a-zA-Z_-]+)/(:any)'] = '$1/admin/$2';
$route['admin/([a-zA-Z_-]+)'] = '$1/admin/index';

You then have an admin section where you can call an admin page via yourdomain.com/admin/blog
yourdomain.com/admin/slideshow

Each of my admin.php controllers extends Admin_Controller while each of my regular module controllers extends Site_Controller.

I'm not sure if that will work exactly the way you want for your site architecture but I hope it helps.


[quote author="gunnarflax" date="1313068328"]This is a hypothetical directory structure for the project:

Code:
-- System
-- Application
---- controllers
---- views
---- models
---- modules
------ admin
-------- controllers
---------- Admin_Controller.php = extending MY_Controller
-------- views
-------- models
-------- core
---------- MY_Controller.php = extending MX_Controller
-------- modules

is this possible? I'm having some trouble planning my project since I don't fully understand how to utilize HMVC effectively.

Can I have modules within modules? They won't be accessed by the URL, they will only be providing modularity to the admin module - which in turn is a module used by the frontend.

Is this at all possible? I've looked at the source of PyroCMS and it looks like they are doing it about the same way.[/quote]
#5

[eluser]gunnarflax[/eluser]
Ok, thanks, I will try this structure and see if it will fit my application. Thank you very much! Big Grin
#6

[eluser]gunnarflax[/eluser]
Just one question since I'm new to HMVC. How should, e.g., a login module be structured? Should the Admin controller have a login method and the login module has just actions, meaning methods which performs the login and logout and no methods providing a view? Or how would you do it?
#7

[eluser]Twisted1919[/eluser]
If you follow the structure i provided for you here: http://ellislab.com/forums/viewthread/196592/
you will go like
Code:
--modules

----admin
------controllers
--------admin.php (this will load the default dashboard)
--------login.php (this will handle the login in the admin area)

----user
-------controllers
---------admin.php (will be the controller that manage the users)
---------login.php (this will handle user login)

Next, you will have a library, say User and from both admin/login and user/login you will call it to login your users.

Every login controller will render the login form and will handle the login process entirely.
#8

[eluser]gunnarflax[/eluser]
[quote author="Twisted1919" date="1313189769"]If you follow the structure i provided for you here: http://ellislab.com/forums/viewthread/196592/
you will go like
Code:
--modules

----admin
------controllers
--------admin.php (this will load the default dashboard)
--------login.php (this will handle the login in the admin area)

----user
-------controllers
---------admin.php (will be the controller that manage the users)
---------login.php (this will handle user login)
Next, you will have a library, say User and from both admin/login and user/login you will call it to login your users.

Every login controller will render the login form and will handle the login process entirely.[/quote]
so the user/controllers/login controller will only be providing the methods and the view is built in admin/controllers/login? Is that what you are saying?
#9

[eluser]Twisted1919[/eluser]
No.
The /admin/login has it's own login.php view file.
The /user/login has it's own login.php view file (not the same as above)

Why is like that?
It's pretty simple, this is the solution i found working best in case for some reason you will have the admin login different than the user login (ie: use other theme + other fields + other checks etc...)

It's just better to keep them separate.
In my case i use themes. A theme for admin panel and another one for frontend. Each theme has it's own views.The admin controllers control the admin theme and the public controllers control the frontend theme.
Is that simple Smile
#10

[eluser]gunnarflax[/eluser]
But if I use the controllers within the modules for navigating the other sections of the admin area I need to load the login module from the other modules to make sure that the user is authorized to view the module's admin page, right? That way it wouldn't be truly modular since the modules depend on each other. Wouldn't it be better to have a method for loading all other modules from within the Admin module's controller? That way I can always make sure that the user is logged in without having to lose the application's modularity.

Or are there reasons for not doing it in the way I mentioned?




Theme © iAndrew 2016 - Forum software by © MyBB