I am trying to intregrate HMVC to codeigniter. I have installed the MX files to thrid_party and uploaded the MY_Loader , MY_Loader and MY_Model to the application/core folder. it is working fine
I have two issues
1) How to add the module routes that overide the application routes
I am accessing module through the link localhost/domain/admin/portfolio
I have tried adding routes.php to the modules config application/modules/portfolio/config/routes.php with below details
$route['admin/portfolio'] = 'portfolio/admin/portfolio';
$route['admin/portfolio/add'] = 'portfolio/admin/portfolio/edit';
$route['admin/portfolio/edit/(:num)'] = 'portfolio/admin/portfolio/edit/$1';
On my root application config already added a routes
$route['admin'] = 'admin/login';
Because of this route 'admin/login' in the application/config/routes.php it is showing page not found. To fix this I have currently added the module/portfolio/config/routes`` above the 'admin/login'. Is there any other method instead of adding it to theapplication/config/routes`.
2) How to access the module view files
I have controller accessing the view files from application/controlles/admin/
$this->load->view('admin/view_header',$data);
$this->load->view('admin/view_portfolio',$data);
$this->load->view('admin/view_footer');
You have placed your Portfolio Controller under
application/modules/portfolio/controllers/admin
which is fine.
Your route (which will hit the index by default) should be
$route['admin/portfolio'] = 'portfolio/admin/portfolio';
Aside: other naming considerations
What I tend to do is to create a controller with admin in the name...
So I would have PortfolioAdmin.php or something along those lines, so I know by the file name, it's admin "Stuff", when I am playing with it in my Editor/IDE.
UPDATE:
In regards to your
Nor this works Modules::run('admin/portfolio', $data);
So you would then use the full controller name... Do not use routes, they are for URLs. Any module you want to call from another module you always use the full name.
Modules::run('portfolio/admin/portfolio', $data);
Related
I am working quite closely with Codeigniter the PHP framework:
http://www.codeigniter.com/
Now I've added this Modular Extensions - HMVC to my Codeigniter framework.
https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/overview
Now, I've created my own module in the modules folder and set up directories for controllers, models and views as instructed. However I'm struggling specifically with custom routing.
I have created the config directory in my module blog directory and I have created the routes.php file within.
Now to access my module in the browser i would go to localhost:8888/blog/ now I'm mostly asking out of curiosity, I wanted to create a custom route so that maybe I could access the page like localhost:8888/posts/ so I thought that setting up the following route would work:
$route['posts'] = 'blog';
or if I had a method called listings I could use
$route['posts/listings'] = 'blog/listings';
However this returns a 404 Page Not Found.
Is it possible to create custom routes like this in a module?
Setting up custom routes for HMVC Easy here are some examples below. You can use same techneique for CI3 Make sure you choose right version from here https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc/downloads go to branches and choose your version The Default is for CI-2
$route['default_controller'] = 'catalog/common/welcome/index';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
// Common
$route['admin'] = "admin/common/login/index";
$route['admin/dashboard'] = "admin/common/dashboard/index";
$route['admin/logout'] = "admin/common/logout/index";
$route['admin/register'] = "admin/common/register/index";
// Users
$route['admin/users/user_edit/(:any)'] = "admin/user/users/user_edit/$1";
$route['admin/users/user_password/(:any)'] = "admin/user/users/user_password/$1";
$route['admin/users/user_key/(:any)'] = "admin/user/users/user_key/$1";
For Example:
admin will be module name.
application modules / admin <-- Admin Module Name
application / modules / admin / controllers / common <-- Sub folder
application / modules / admin / controllers / users <-- Sub folder
Please watch this great tutorial for beginners on HMVC https://www.youtube.com/watch?v=8fy8E_C5_qQ
You can also download Htaccess from here http://www.insiderclub.org/downloads you may need to join for free to download David's Insider Club suitable for codeigniter.
Please refer this question Codeigniter: Error in loading HMVC sub module model
Now I am setting up second level of module like
mysite.com/admin/hr/positions/
Directory structure is this
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/hr/
modules/admin/controllers/hr/
modules/admin/views/hr/
modules/admin/models/hr/positions
modules/admin/controllers/hr/positions
modules/admin/views/hr/positions
Now I have respective MCV for every directory. Example Admin, Dashboard, HR and Positions. The system works fine till HR so if I enter site.com/admin/hr/ it is giving output
but when I try to access positions page site.com/admin/hr/positions/ it is giving me 404 no idea what is wrong in it?
Is it because that module is under HR ?
I am loading view $this->load->view('admin/hr/positions/index', $this->data); this way.
The controller name is part of the path as well.
To access function index() of class Positions in /admin/hr/positions/ you need to call /admin/hr/positions/positions/.
To avoid that, move the Controller file positions.php to /hr/.
The path structure of CodeIgniter is always /path/to/controller/controller_name/function_name/as/many/parameters/as/you/want.
I wrote a controller named Admin with method index and placed as /application/controllers/admin.php for URL http://localhost/admin.
Then I wrote another controller named Account inside /application/controllers/admin/ folder, with a method login for URL http://localhost/admin/account/login.
But the problem is when I visit /admin/account/login I got a 404. I don't know why? Or how can I define this 2 path in my controllers?
I also faced the same problem but for only solution was to either rename the subfolder name or rename the outside controller name.
Try put admin/account/login before admin, something like this:
$route ['admin/account/login'] = 'admin/account/login';
$route ['admin'] = 'admin/index';
In my Laravel 4 application's root directory, I have a folder themes. Inside the themes folder, I have default and azure.
How can I access view from this themes/default folder in a specific route.
Route::get('{slug}', function($slug) {
// make view from themes/default here
});
My directory structure:
-app
--themes
---default
---azure
I need to load views from localhost/laravel/app/themes/default folder. Please explain this.
This is entirely possible with Laravel 4. What you're after is actually the view environment.
You can register namespace hints or just extra locations that the finder will cascade too. Take a look here
You'd add a location like so:
View::addLocation('/path/to/your/views');
It might be easier if you namespace them though, just in case you have conflicting file names as your path is appended to the array so it will only cascade so far until it finds an appropriate match. Namespaced views are loaded with the double colon syntax.
View::addNamespace('theme', '/path/to/themes/views');
return View::make('theme::view.name');
You can also give addNamespace an array of view paths instead of a single path.
Here I am not accessing my project from public folder. Instead of this I am accessing from project root itself.
I have seen a forum discussion about Using alternative path for views here. But I am little confused about this.The discussed solution was,
You'd add a location like,
View::addLocation('/path/to/your/views');
Then add namespace for theme,
View::addNamespace('theme', '/path/to/themes/views');
Then render it,
return View::make('theme::view.name');
What will be the value for /path/to/ ?
Can I use the same project in different operating system without changing the path?
Yes, we can do this using the following,
Put the following in app/start/global.php
View::addLocation(app('path').'/themes/default');
View::addNamespace('theme', app('path').'/themes/default');
Then call view like the default way,
return View::make('page');
This will render page.php or page.blade.php file from project_directory/app/themes/defualt folder.
I've developed a theme package for laravel 5 with features like:
Views & Asset seperation in theme folders
Theme inheritence: Extend any theme and create Theme hierarcies
Try it here: igaster/laravel-theme
\View::addLocation($directory); works fine but the new right way to do it is using loadViewsFrom($path, $namespace) (available on any service provider).
In my project, have setup an admin panel under a folder inside controllers folder like this
controllers/admin_panel/dashboard.php
And when we open it like this, it loads dashboard controller default
http://www.mysite.com/admin_panel
Now I have added a page controller on root level to load the page content from database. So here I have some a setup of kind of CMS. To load the page controller, I have added a condition in routes as below
$route[':any'] = "page";
But what it is doing now is, when I try to open admin_panel, it loads the page controller.
So I want to add a kind of exception condition here like route any except admin_panel
Any suggestions how can I achieve this ?
Thanks in advance.
You can just define another route right above that one that will take you to the admin panel. In CodeIgniter, routes will run in the order they are defined.
$route['admin_panel'] = 'admin_panel';
$route[':any'] = 'page';
You should be able to access the admin_panel with the above routing.