Jump to content

ModuleFrontController is not accessible


Recommended Posts

So, here's is my custom module that I created. Please see attached.

 

So I have a problem where ModuleFrontController is not accessible it gives me 404 when I try to access it, using this url, that I generated with this code: 

$this->context->link->getModuleLink($this->name, 'ajax');

It returns this url: http://localhost/test/module/recommended_products_custom/ajax

When I visit it, it returns 404, I changed my module's folder name and class and module name, you can see the current structure in the image.

And it is strange. It no longer works, could anyone please tell me if I made a mistake renaming, as I don't see it myself and I really feel like I'm following the right naming conventions.

Any help is really appreciated.

prestashop.PNG

Edited by Elvinas (see edit history)
Link to comment
Share on other sites

31 minutes ago, endriu107 said:

You need to register controllers by $this->controllers = array('ajax');

 

Unfortunately it did nothing. Seems really weird, impossible to identify what is wrong. It seems that folder names, module name, and class names are all correctly named.

presta.PNG

Edited by Elvinas (see edit history)
Link to comment
Share on other sites

11 minutes ago, endriu107 said:

In initContent did you set template path?

Yes, I did. Please see attached. I think the problem is probably somewhere else, but regardless it is really weird. Because personally I'm not sure if the template path could be related somehow, as I tried to echo out some text at the very beginning of initContent() function and still I got 404 error, so it happens even before the template is fetched.

cide.PNG

Link to comment
Share on other sites

Just now, Elvinas said:

Yes, I did. Please see attached. I think the problem is probably somewhere else, but regardless it is really weird. Because personally I'm not sure if the template path could be related somehow, as I tried to echo out some text at the very beginning of initContent() function and still I got 404 error, so it happens even before the template is fetched.

cide.PNG

Please call parent::initContent(); in your initContent function 

Link to comment
Share on other sites

I uploaded an image, please see attached.

So my module's folder name is: 'recommended_products_custom

The main module's file name is: recommended_products_custom.php (the same as folder name + .php)

The main module's file class name is: Recommended_Products_Custom 

 

 

The front controller file name is: ajax.php and class name: Recommended_Products_CustomAjaxAjaxModuleFrontController when it should have been Recommended_Products_CustomAjaxModuleFrontController (only one Ajax word).

 

And to my surprise it still does not work. Even after addint parent::initContent(); and such. Looks like I found the naming problem and it still didn't solve this, just wow.
 cide.thumb.PNG.e1b4d555f03b65586535e32ef169e149.PNG
 

 

Thanks guys for trying to help me :)

Edited by Elvinas (see edit history)
Link to comment
Share on other sites

18 minutes ago, Elvinas said:

Nope it's not. Sorry maybe I wasn't clear, I fixed the typo that I made but it still didn't solve it.

 

Just try to comment this line  /1.7.7.0/modules/recommended_products_custom/controllers/front/ajax.php

   public function __construct()
    {
        $this->templateFile = 'module:recommended_products_custom/views/templates/hook/recommended_products_custom.tpl';
    }

 

 

you will see the message in browser  Direct access not allowed.

in my case the frontend url is  http://localhost:8888/ps/1.7.7.0/en/module/recommended_products_custom/ajax

Hope it will help you.

 

Thank you

Link to comment
Share on other sites

Thanks guys for your help. Unfortunately I can't try out your solutions for now. I'm unable to delete the module from prestashop. It says: Cannot uninstall module recommended_products_custom. The module is not installed.

I tried deleting the module directory manually, it did disappear, but when I copy and paste it back it shows that it is somehow installed, and I can't uninstall and make a fresh install. So looking for the info how to solve it, then I can try your provided examples. I really appreciate time you took to answer me.

Link to comment
Share on other sites

Please change it 

 

public function hookHeader()

{

$this->context->controller->addJS($this->_path . '/views/js/front.js');

}

to

public function hookHeader()

{

$this->context->controller->addJS($this->_path . 'views/js/front.js');

}

other wise it will add a extra /

<script type="text/javascript" src="http://localhost:8888/ps/1.7.7.0/modules/recommended_products_custom//views/js/front.js" ></script>

 

Thank you

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...