codeigniter hmvc and main controllers,models and views - codeigniter

I decided to try HMVC pattern with codeigniter but I have some doubts about how to think about and build my website structure using this pattern so I have some questions:
if the main focus is on modules what is the purpose of application/controllers, application/views and application/models.
can I remove the aboved folders and route the default controller to some module?
if I have 3 controller each of them haveing unique $type and $id but all of them need to call a controller that control every thing about comments in website and just pass $type and $id, will this confilct with HMVC pattern?

the purpose of this 3 folders is to have the most 'generic' things on your application. For example, if you have a crud model, you should have on the main model folder, outside your modules. Other example, if you have a generic header/footer view you should have it in the main views folder, and so on.
You shouldn't remove this folders, but you can set the default controller just adding the module in front.
I think this is not a problem, it will not be any conflict on hvmc pattern
here you have a good guide

Related

How to call two controllers in one controller folder when using hmvc CodeIgniter?

I have the following folder structure
Modules
--controllers
--User
--Product
How can I call the product controller from user controller from one particular function?
When I run this url http://[::1]/stagingweb/index.php/user/product I get the error 'The page you requested was not found'.
it looks like you have a problem to understand the concept of hmvc here
HMVC stands for Hierarchical model–view–controller, which means in Wiredesignz HMVC there is an additional variation called modules added to the classical MVC pattern used by Codeigniter.
in your case if you have users and products, its probably the best to create 2 modules (users and products).
So your folder structure would look like
modules
- users
- controllers
User.php
- models
- views
- products
- controllers
Product.php
- models
- views
in Wiredesignz HMVC Integration there is a class MX_Controller, so every module controller has to extend from it.
an example
class Product extends MX_Controller{}
And if you want to call another modules controller within your specific controller you simply have to call
$return = modules::run('products/product/your_function');
Though in most cases it's probably a cleaner solution to just call the models from the other modules instead of executing a controllers function...
The entire process is very well documented here

Laravel 4 - Accessing Folders

I am new to Laravel 4, and I come from a Zend Framework background. I'd like to create a folder app/forms and keep all my forms there. How can I refer to the form in the controller and within the view.blade files?
By default, the root of the view files folder is app/views so if you create a folder in views like app/views/forms then you may refer the form by it's name from a controller like:
$form = View::make('forms.formfile');
Here, formfile is the name of the file that contains the form and it could be formfile.blade.php and to refer/include the form file from a view you may use #include:
// In a blade view file
#include('forms.form1')
Assume that, form1 is a blade view inside the forms folder and saved as form1.blade.php, you may also use sub-folders inside the forms folder, for example in views/forms/user folder you may keep a view named index.blade.php and use it like:
// From a controller
$userForm = View::make('forms/user/index');
From a view file: (folders are separated by .)
#include('forms.user.index') // file: app/views/forms/user/index.blade.php
You can also nest views in the controller, check the manual for more.
From the standpoint of Laravel, HTML forms (and all presentation related things ) belongs to app/views/ folder. Exceptions are package specific views. For example some commands has their own stubs and views and they are usually stored inside package.
Laravel is very flexibile, and you can move things around and create new folders and namespaces. You just have to tell composer that you are changing Laravel default structure, and dumpautoload. That is if you only want to create new folder with internal reference. If you want something with more scope and visibility you'll have to bind that to container, so that will be visible inside whole application.
You are coming from the Zend world, so I can understand that you want to move some of Zend "flavour" to Laravel. Although is it possible, I would really recommend you to take some time and learn how Laravel works. There are some great ideas and design inside. Of course, Zend has its own quality, but hey - this is Laravel :)

How to load a library from Module using codeigniter modular extensions

i need to load a library from my module using Modular Extensions
my structure like this
modules/
modules/categories/library
categories_class.php
modules/categories/controllers/
categories.php
I need to load categories library in categories controller .
any one cane help me?
I see two problems..
Problem 1
According to your question, your categories module is not organized properly. The whole purpose of HMVC is compartmentalizing of code e.x; modules. Given your present question how does that structure allow you to copy your modules folder and paste it into another app? Answer: It doesnt..
Follow the example below
It should be the following from the app root:
/application/
config
modules/
categories/
views
controllers/
categories.php
libraries/
categories_class.php
models
libraries
core
controllers
Problem 2
per the user guide: https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/wiki/Home
You must prefix the module name in front of anything referenced inside the modules folder.
e.g: $this->load->library('module/library');
or in your case: $this->load->library('categories/categories_class');
I have attempted previously to exclude the modules folder name and have never gotten it to work.
Controllers can be loaded as class variables of other controllers
using $this->load->module(’module/controller’); or simply
$this->load->module(’module’); if the controller name matches the
module name.
Any loaded module controller can then be used like a library, ie:
$this->controller->method(), but it has access to its own models and
libraries independently from the caller.
I have another perspective for this error behavior, that make me spend about 3 hours, actually I am always using combination of Uppercase and Lowercase on my custom libraries on Codeigniter.
For wiredesigz of Codeigniter HMVC, remember the libraries loader behavior as same as CI itself, always use lowercase of your library classes name instead of actual class name (Maybe combination of uppercase and lowercase)

How to design Joomla style plugin in CodeIgniter

First of all, I want to describe my project architecture:
My project uses jqGrid.
Controllers only define the Grid.
Then Models retrieve the Data for the Grid.
Models are used to Add/Edit/Delete Records.
Views are used to show the page.
Consider, I have 10 different kinds of customers for my project. My project is a hosted solution which serves my all 10 customers from a single source. Among them, eight needs the exact same as I created. Only two are different than the common.
For example, imagine that I want to show a product list. As my project is a hosted solution I can't change the menu by which I can change the controller for the said two customers.
To solve the problem, I want to implement plugin system like Joomla.
How can I do that in CodeIgniter?
Edit
I am using CI 1.7.2.
Maybe it will help you:
There is module solution for Codeigniter HMVC module . It gives you way to divide application logic into modules with their own MVC structure (each module will have it's own model\view\controller).
After installing this module into CI you'll be able to call another module from main app's controller (or view or model) like that:
<?php echo modules::run('module/controller/method', $param, $...); ?>
So I think you can use modules functionality provided by this extension to build per customer modules structure based on customers roles.

Codeigniter HMVC and CMS

I am using Codeigniter with the HMVC Modular extension and have a backend CMS area for managing website content. I am routing the base URL + "admin" (http://localhost/cms/admin) to controller methods with the prefix "admin_".
e.g. function admin_index() {...}
And here is my routing:
$route['admin/([a-zA-Z]+)/(:any)'] = "$1/admin_$2";
$route['^admin/(:any)(/)?'] = "$1/admin_index";
$route['^admin(/)?'] = "dashboard/admin_index";
$route['admin/logout'] = "login/admin_logout";
With the HMVC it is not routing correctly now. Here is what happens:
URL: http://localhost/cms/admin/faqs
Directory: modules/faqs/controllers/faqs - index method
--
here is where it breaks
--
URL: http://localhost/cms/admin/faqs/categories
Directory: modules/faqs/controllers/faqs - categories method (does not exits)
Desired: modules/faqs/controllers/categories - index method
How can I use HMVC while maintaining the "admin" are of the website?
You are making life a bit too tricky by putting frontend and backend functions in the same controllers. Have a look at my article on how to create an admin structure in CodeIgniter.
I'm working on something similar, and implemented a swapping like you did (3rd option) and it worked fine.
I tried to implement a front controller to handle the admin section, and run modules with HMVC modules::run() and buffer the output as I wish, but then I have faced another issue, you will have to change the URI schemes from / to _ or something else, since you wont be able to send module segments as parameter to your controller because CI relies on "/" for it's routing mechanism.
The only way is to emulate the admin section as Phil suggested, but there is another option to still have control over the code implemented by anyone using your CMS.
You could extend CI_Controller (or MX_Controller in case you are using HMVC) and add an Admin_Controller which will handle your logic and control what modules can do.
Have a look at this CodeIgniter Base Classes: Keeping it DRY

Resources