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.
Related
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);
I'm trying to load a controller inside another controller.
$data['com_top_menu'] = $this->load->controller('account/com_top_menu');
However, this seems to not work when I'm trying to load a controller that is located in the same folder as the controller I'm loading it from.
Tried loading controllers from other folders and seem to not load as well. It seams to load only from the 'common' controllers folder.
Edit:
Actually it seems that the controller is loading. If I place an echo in the middle of the loaded controller it will show the output before the template rendered. So, it looks like the controller is loaded and just doesn't output anything through the rendered view, unless it is a controller inside the common folder.
Files are all in place, controller loads, it just doesn't output anything through the view.
Few things for to load controllers-
1st - you can only load controller from same folders (admin/ catalog).
2nd - you can load controller from any subfolder, just need to pass correct loading path.
3rd - If Opencart hasn't that file than it will not display any error, result will be null/ false.
4th - If you are defining any function name then it will call that function else will call index function so in your case index.
5th - Please use this
return $this->load->view('your.tpl', $data);
Instead of
$this->response->setOutput($this->load->view('your.tpl', $data));
6th - Please enable your debug mode from php/ admin so that you will know any error if your code is throwing. Clear your error.log and then try to load controller.
7th - If these all points are code is not working then do 1 thing - add a blank controller with index function and just add one line so that you can return it's result from view then just
echo 'here';
In your view. If OC is not returning this result it's mean you have error in Opencart files else there is error in your code.
You can say these are same in a way (i am not saying completely and don't want to hurt anyone feelings ;)) but this code
$this->load->controller('account/com_top_menu');
is equal to (based on your autoloader)
$obj = new ComTopMenu; //assuming your class name
$data['com_top_menu'] = $obj->index();
so for your solution please check
- you have file com_top_menu.php in your catalog > controller > account >
- your file class name must be ControllerAccountComTopMenu (or any uppercase or lowercase combination but without _)
- your class must have index function because in your case it calling index.
I am new to yii framework. On yii version:2.0.1 I have created a module in which I tried to generate a CRUD model using the gii functionality. After putting the model class, controller class and view path when I clicked on generate gii showed all the files has been created successfully. But when I tried to view, below message has been shown to me,
The view file does not exist :
C:\xampp\htdocs\advanced\backend\modules\settings\views\companies\index.php
I found the view files in web directory not in the path I entered. Hence the error.
Here is my inputs to gii,
Model Class:
backend\modules\settings\models\Companies
Search Model Class:
backend\modules\settings\models\CompaniesSearch
Controller Class:
backend\modules\settings\controllers\CompaniesController
View Path:
backend\modules\settings\views\companies
When I click generate I have given below message :
Generating code using template "C:\xampp\htdocs\advanced\vendor\yiisoft\yii2-gii\generators\crud/default"...
generated modules\settings\controllers\CompaniesController.php
generated modules\settings\models\CompaniesSearch.php
generated backend\modules\settings\views\companies\_form.php
generated backend\modules\settings\views\companies\_search.php
generated backend\modules\settings\views\companies\create.php
generated backend\modules\settings\views\companies\index.php
generated backend\modules\settings\views\companies\update.php
generated backend\modules\settings\views\companies\view.php
done!
Does anybody have any idea why is it happening.
Thanks in advance.
I solved similar problem by changing
backend\modules\settings\views\companies
into
#backend/modules/settings/views/companies
Hopefully it helps someone in future
You missed one final folder and alias in View Path. It should be #backend\modules\settings\views\companies.
As you can see in creation log, the generated files are in wrong place (root views folder), that's why the error is thrown.
Have the same problem. Solved entering #backend/modules/settings/views/companies instead backend\modules\settings\views\companies.
See on slashes.
For view path in CRUD generator, enter the absolute or full path. For example
/home/developer/workspace/advanced/backend/views/<your view folder>
put this in the VIEW PATH
#backend/modules/settings/views/companies
and it's done!
I have tried with absolute path i,e
C:/xampp/htdocs/advanced/backend/modules/settings/views/companies
It worked for the absolute path.
I tried this is working by entering:
/Applications/XAMPP/htdocs/advanced/backend/modules/settings/views/companies
I hope you can do it well.
I'm using the advanced theme
Here is my Gii setup in case it is helpful for anyone
module generator
----------------
module class: backend\modules\posts\Module
module id: posts
model generator
---------------
table name: posts
model class: Posts
namespace: backend\modules\posts\models
Enable I18n: checked. category: app
CRUD generator
--------------
Model class: backend\modules\posts\models\Posts
Search model class: backend\modules\posts\models\PostsSearch
Controller class: backend\modules\posts\controllers\PostsController
View path: #backend/modules/posts/views/posts
Enable I18n: checked. category: app
Enable pjax: checked
If you are using some non-default user management (like amnah module),
you need to change Users::className() in the models\Posts.php to
\amnah\yii2\user\models\User::className()
Previously I put a model into the incorrect directory when wanting to achieve an absolute path (address it absolutely as it seems to be more often functional) -
app/backend/modules/settings .
Notice the 'app' in the beginning (the /app is the main directory in Yii starter kit) which I thought would avoid the relative path but must NOT be there nor #mail sign, but on the contrary, it did the opposite - it appended it relatively with its absolute length to the /document root directory, basically duplicated it,
"app/myproject.com/app/backend/modules/settings"
So it unwinds from the model location, the causes of Gii complaints about incorrect paths or put also controllers the incorrect way.
Also strangely enough for views in contrast to models, it had to be put the upper mentioned different way with the # relative reference sign annotation (which was not allowed to be used for controllers or models at the time of writing)
#backend/modules/settings/views/companies, otherwise it appended the directory tree into the document root, again concatenated - the web directory of backend backend/web (backend/modules/settings/views/companies)
I think this is a route issue but I'm not sure. I have a page with this URL:
siteurl.com/kowmanger/titles/titles/edit/$id
I'm trying to find out that when I'm on this page I load the titles page it says page not found so I need to tell it that the $id is just a paramter so I can use it to get the data of the title.
UPDATE :
So I decided to change my titles controller so that there's a edit and add function inside of the titles controller that way they dont' have separate controllers when they are in fact methods.
So now I have:
kansasoutalwwrestling.com/kowmanager/titles/titles - list of titles
kansasoutalwwrestling.com/kowmanager/titles/titles/add - addnew form
kansasoutalwwrestling.com/kowmanager/titles/titles/edit/$id - edit form
I don't have any routes set up so far for this. For some reason though I"m getting the same page for both of these page.
kansasoutalwwrestling.com/kowmanager/titles/titles/add - addnew form
(right link url) kansasoutalwwrestling.com/kowmanager/titles/add -
addnew form
I need a route so that it'll show the correct url if the add method is accessed.
Also I need to set up a route so that if the correct edit link is accessed it sees the id attached to the end of the url and it'll accept it so that I can do a my database query to get the title data.
UPDATE: So to reiterate I have a module(subfolder) called titles. Inside of the module I have a controller called titles and inside of that controller I have 3 functions called index(), add(), edit().
I tried using Chris's suggestion on the routes but its not routing correctly. Also wanted to mention I'm using wiredesignz modular separation framework if that matters.
Any additional ideas?
Possible answer based on your post, not one hundred percent your entire structure but if i had to guess based off the post I would try this as my routes first..
$route['titles/titles/edit/(:any)'] = 'titles/titles/edit/$1';
$route['titles/titles/add'] = 'titles/titles/add';
$route['titles/titles'] = 'titles/titles';
$route['titles'] = 'titles/index';
Are you using custom routing in your configuration files ?
The general routing protocol used by codeigniter is like this:
domain.com/controller/methode/param1/param2/param3
This being said, your url
siteurl.com/kowmanger/titles/titles/edit/$id
corresponds to something like this :
class Kownmanger extends CI_Controller
{
public function titles($titles, $action, $id)
{
}
}
In case you are using sub-folders in your controllers folder, what I have just said will change, Could you please tell us what's your directory structure ?
In one of my application I integrated a codeigniter template using HOOKS method... Its working pretty well ... The hooks/ template will call in Controllers Constructor ..
the 'default.php' is located in views folder ...
But I need 2 templates for my proj .. Can any one help me how to handle this ?
Please help
Look for the 'Themes' library... each theme has its own folder inside the views folder...and its called like this : 1st line is template 2nd line is the page
$this->themes->set_theme('theme');
$this->themes->set_template('template')
then in your controller its invoked using: $this->themes->view('view');
simple insert a {page_content} tag into your template where you want to insert the page code.
It may still be available on the CI wiki.