OpenCart 1.5.6; Theme: Default.
I've created a new module 'Seller' cloned by 'Manufacturer' ... Admin side & Front side is working okay, means adding / editing / saving data is working okay, except an issue.
When I click on 'Seller' link at product page (frontend), it shows 404 error / page not found, ideally it should work same as Manufacturer module works, should open seller's page with list of products by the same seller.
What could be the reason? Because I don't see any error in log files / VQMOD, it just shows 404 error.
Any clue?
Probably this happened here:
Let's assume Your seller URL is http://my.domain.com/index.php?route=product/seller&seller_id=1.
Now the route part product/seller tries to load this controller file:
catalog/controller/product/seller.php
^^^^^^^^^^^^^^
and while there is no action specified (which would be e.g. product/seller/showList) the index action is called. This all means, that You need to have the above mentioned file, which has to contain a class ControllerProductSeller extending from Controller and this class has to have method index implemented.
This would look like
class ControllerProductSeller extends Controller
{
public function index()
{
// ...
}
// ...
}
After this is fulfilled You should not receive a 404 error.
I can see You are completely new to OpenCart and new modules creation (reminds me of my starts) and my advice is: look and discover how the things in OpenCart are done, copy+paste+rename wisely. Most of errors like this (and missing template, language, model files, undefined method names etc) are caused by improper renaming, or in other words, by hot head and quick fingers... Slow down and start thinking a little bit about what are You doing and what needs to be done.
Related
I'm having an issue where a route is returning a blank page. I am using Homestead as my dev environment and I'm unsure how to debug.
The /storage/logs/laravel ... isn't returning any exceptions when I visit the white page.
web.php (where it's failing):
Route::get('/clinic/register', 'ClinicController#register');
Controller.php:
public function register()
{
return view('clinic.register', ['specialisms' => Specialism::pluck('specialism', 'id')]);
}
Yet when I visit /clinic/register I am shown a blank white page. How can I see why it's failing? Surely a white page will return an exception somewhere?
As you have not provided your entire route setup. This answer is my best guess. See if it helps.
Your issue hint at improper route setup. If you have created a clinic resource then clinic/register route should precede it.
// clinic/register route should come first
Route::get('clinic/register','ClinicController#register');
// followed by rest of the routes which resource will create
Route::resource('clinic','ClinicController');
The reason behind getting a blank pages is because Route::resource will create some route with wildcards.
For e.g. clinic/{clinic} which will map to show method on controller. So when you make a get request to clinic/register it will be mapped to this show method instead of your register method.
One possibility for not getting any errors is your show method does not have any code yet. Hence, a blank response.
To summarize: Order in which you register your routes matters
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 using SS 3.02 and have made a lots of modification in the core files. I am facing the issue that I am trying to set the color of the navigation background dynamically. This works fine for pages other than security/login page. Suppose I am getting the value in $navbgcolor, this shows up well on home page or about us page or any other page. But this does not show up on the Security/login page. Any help would be greatly appreciated. Thanks.
Firstly, it is never a good idea to alter the core files as this prevents you from easily updating your version of SilverStripe. You could miss out on bug fixes and important security updates.
The reason this isn't working on the login page is because the login page works from the Security controller which directly extends Controller. Your code (presumably in Page_Controller) will be completely bypassed.
Here is a way you could apply your code to all controllers, without touching the core:
<?php
class MyControllerExtension extends Extension {
public function onAfterInit() {
//... Your code here...
}
}
In your config file you would apply your new controller extension to Controller.
If you're using _config.php
Object::add_extension("MyControllerExtension", "MyControllerExtension")
If you're using YAML (recommended)
Controller:
extensions:
- 'MyControllerExtension'
You can learn more about extensions here: http://doc.silverstripe.org/framework/en/reference/dataextension
Also to let you know, you can create specific template file for the Security login pages by creating action sub-templates. Example is if you created a file in your theme called "Security_login.ss" you can call in variable, change the mark up etc.
Note the convention here is the filename is called the name of the class in this case "Security" then "_" followed by the name of the action to be rendered by your controller ("login" in this case).
As mentioned by micmania1, the golden rule for developing in SilverStripe is...
"Don't hack the core or modules!"
Instead as pointed out use extensions to decorate classes, or use subclasses if you have to.
I have the following (basic) route set up in a CI-based web app:
$route['sms/resend/(:num)/(:any)'] = 'sms/resend/$1/$2';
The controller + 'resend' method:
class Sms extends CI_Controller {
public function resend($to, $message) {
// my code
}
}
Logically speaking, anything that doesn't fit the route should be directed to a 404 page instead of the resend() method within the sms controller. This isn't the case, however. The following URL, for example, isn't redirected correctly, it goes to the same controller+method:
http://myapp/sms/resend/uuuu/WhateverMessage
What could be the problem?
After a bit of digging, I've come to understand that CI's default routing does not get deactivated when a default route related to a specific controller/method pair is added. That being said, if a URL does not fit the route $route['sms/resend/(:num)/(:any)'] = 'sms/resend/$1/$2', then the same URL is run through CI's default routing mechanism as a fallback, so it still takes me to the resend method of the sms controller. To prevent this from happening, I needed to add another custom route that follows all others related to the sms resending, that redirects any other url to a different controller+method. If this controller doesn't exist, you get the default 404 page.
So the final /config/routes.php file:
$route['sms/resend/(:num)/(:any)'] = 'sms/resend/$1/$2';
$route['sms/checkoperator/(:num)'] = 'sms/checkoperator/$1';
$route['sms/(:any)'] = 'somewhereovertherainbow';
I think the rout file is just for rerouting. Your URL don't fits the routing Conditions so it don't gets rerouted! So it goes the normal way wich is the same (in this case!)
Something like this could work!
(! :num) /(:any) '] = error page (or not existing page)
So every request wich doesn't start with a number gets redirected to the error page!
The syntax might be wrong!
This would work great :
$route['sms/resend/[^0-9]/(:any)'] = 'errorpage';
You have to replace the error page by something ;)
I am currently working on a Magento extension, and I have overridden a core controller, which works fine.
I have now added a new action to my controller. Problem is that whenever I call the action a blank page is produced. If I echo something it is displayed correctly.
Therefore I dug into the core of the Customer module and controllers. I saw there that methods like indexAction() implement the layout this way:
<?php
public function indexAction()
{
$this->loadLayout();
$this->_initLayoutMessages('customer/session');
$this->_initLayoutMessages('catalog/session');
$this->getLayout()->getBlock('content')->append(
$this->getLayout()->createBlock('customer/account_dashboard')
);
$this->getLayout()->getBlock('head')->setTitle($this->__('My Account'));
$this->renderLayout();
}
I transferred this to my own action and the layout is now rendered correctly. Now for the question:
No matter what I enter into the ->createBlock('...') call, nothing is rendered into the content area.
How do I specify the location of my own block to be rendered as the content of the page while still decorating it with the layout?
I tried fiddling with the xml files in /design/frontend/base/default/layout/myaddon.xml but couldn't really make it work.
Covering the entirety of the Magento layout system in a single StackOverflow post is a little much, but you should be able to achieve what you want with the following.
$block = $this->getLayout()->createBlock('Mage_Core_Block_Text');
$block->setText('<h1>This is a Test</h1>');
$this->getLayout()->getBlock('content')->append($block);
Starting from the above, you should be able to build up what you need. The idea is you're creating your own blocks, and then append them to existing blocks in the layout. Ideally, you're creating your own block classes to instantiate (rather than Mage_Core_Block_Text), and using their internal template mechanism to load in phtml files (separating HTML generation from code generation).
If you're interested in learning the internals of how the layout system works, you could do a lot worse than to start with an article I wrote on the subject.