Jump to content

[SOLVED] Link not working creating a Prestashop 1.5 module


Recommended Posts

Hi all!

I'm trying to follow the official tutorial for creating a module in PS 1.5. In the one for PS 1.4 I had no problem, but now, in the 1.5 version, I cannot make a link to custom controller working..
 

My custom module is named "endriutest".
 

This is a piece of code in my "endriutest.php"

function hookDisplayLeftColumn($params) {
   $this->hookDisplayHeader();
   $this->context->smarty->assign(array(
	'endriu_test_link' => $this->context->link->getModuleLink('endriutest', 'display')
   ));
   return $this->display(__FILE__, 'endriutest.tpl');
}

and in the "endriutest.tpl"

<a href="{$endriu_test_link}">Vai a una pagina custom</a>

but when I click on the link, which comes out like "http://mydomain.it/module/endriutest/display", Prestashop can't find the page and give me an error.. I have "display.php" in my module's root and it should show a simple text like this

Welcome to this page!

I can't find the problem because I think I'm doin' the right things like the tutorial explains but something goes wrong somewhere..

Any ideas? Thank you :)

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

I'm following that guide, but when I tried to create the controller it didn't work (same error, page not found), so I turned back to the lines that say:

Embedding a template in the theme

The link that the module displays does not lead anywhere for now. Let's create the display.php file that it targets, with a minimal content, and put it in the module's root folder.

display.php
Welcome to this page!

Click the "Click me!" link: the resulting page is just that raw text, without anything from the theme. We would like to have this text embedded in the theme, so let's see how to do just that.

and tried to insert in the "display.php" only that line of raw html, but it doesn't appear anyway.. page not found...

Link to comment
Share on other sites

Well, it's all written in my first post...

1) the first piece of code shows a part of my main module's class, where I set the hook for left column and, after assigning a smarty variable with the result of a call to "getModuleLink", I show the content of the main template
2) the second piece of code shows a part of my main template, where I use the variable assigned before to set the "href" attribute of a link
3) the third and last part is the content of my "display.php", which now doesn't contain a controller (I tried this before with same results) but just raw text;

Now, following the guide, the raw text should appear on a new page when I click on the link builded before, but no, it reports a "page not found" error..
So I wonder if I'm building the link correctly, but it seems I'm doin' just what the guide says, and the link itself seems to be correct, because it appears like <http://mydomain.it/module/endriutest/display"> where, obviously, "mydomain" is just to hide my real test domain I'm workin' on..

 

Hi all!

I'm trying to follow the official tutorial for creating a module in PS 1.5. In the one for PS 1.4 I had no problem, but now, in the 1.5 version, I cannot make a link to custom controller working..
 

My custom module is named "endriutest".
 

This is a piece of code in my "endriutest.php"

function hookDisplayLeftColumn($params) {
   $this->hookDisplayHeader();
   $this->context->smarty->assign(array(
	'endriu_test_link' => $this->context->link->getModuleLink('endriutest', 'display')
   ));
   return $this->display(__FILE__, 'endriutest.tpl');
}

and in the "endriutest.tpl"

<a href="{$endriu_test_link}">Vai a una pagina custom</a>

but when I click on the link, which comes out like "http://mydomain.it/module/endriutest/display", Prestashop can't find the page and give me an error.. I have "display.php" in my module's root and it should show a simple text like this

Welcome to this page!

I can't find the problem because I think I'm doin' the right things like the tutorial explains but something goes wrong somewhere..

Any ideas? Thank you :)

Link to comment
Share on other sites

Yes, I said I followed guide and the guide, before creating the PHP logic of the controller, shows inserting raw text in "display.php" to make a simple text come out. But it doesn't happen on my side.

This is the real problem as seems like the "display.php" script has not been called at all. Anyway, if you want to see what I inserted in the "display.php" to make it a "real" controller, here is the code:

class endriutestdisplayModuleFrontController extends ModuleFrontController {
	public function initContent() {
		parent::initContent();
		$this->setTemplate('display.tpl');
	}
}

and the result is the same, page not found.

 

but you said that you followed guide (created controller) and i don't see it there.

Link to comment
Share on other sites

Ok, solved.

There is an error in the official guide, where it says

 Let's create the display.php file that it targets, with a minimal content, and put it in the module's root folder.

If you put display.php in the module's root folder, you will have "page not found" error like me. After some rows, the guide says:

Let's explore display.php, our first PrestaShop front-end controller, stored in the /controllers/front folder of the module's main folder:

If you put display.php in /controllers/front, this will work!

Maybe that is a section of the old version (1.4) of the guide that nobody has removed. Furthermore, it's not specified where I should put the template file, but trying, I found that it has to be put in /views/templates/front

It would be good to modify the guide to teach the right steps <_<

Thanks anyway for help!

  • Like 3
Link to comment
Share on other sites

  • 1 month later...

Ok, solved.

There is an error in the official guide, where it says

 Let's create the display.php file that it targets, with a minimal content, and put it in the module's root folder.

If you put display.php in the module's root folder, you will have "page not found" error like me. After some rows, the guide says:

Let's explore display.php, our first PrestaShop front-end controller, stored in the /controllers/front folder of the module's main folder:

If you put display.php in /controllers/front, this will work!

Maybe that is a section of the old version (1.4) of the guide that nobody has removed. Furthermore, it's not specified where I should put the template file, but trying, I found that it has to be put in /views/templates/front

It would be good to modify the guide to teach the right steps <_<

Thanks anyway for help!

 

 

I had the same problem, follow endriudb instructions to get the tutorial example module working.!! shame that I found it too late. But its a must do, for newbies&everywone , if you dont write  display.tpl  into:

 

mymodule/views/templates/front

 

the template will not show.

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

I had the same problem, follow endriudb instructions to get the tutorial example module working.!! shame that I found it too late. But its a must do, for newbies&everywone , if you dont write  display.tpl  into:

 

mymodule/views/templates/front

 

the template will not show.

If you want to test mymodule, same as official guide, but no need to re-write it,

 

here is a link to download it: 

 

http://b.96.lt/Ny

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

See this:

 

I follow the tutorial ( http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module#CreatingaPrestaShopmodule-Technicalprinciplesbehindamodule )

too and:

I make this:

public function hookDisplayLeftColumn($params)
{
  $this->context->smarty->assign(
      array(
          'my_module_name' => Configuration::get('MYMODULE_NAME'),
          'my_module_link' => $this->context->link->getModuleLink('mymodule', 'display')
.....................
and the real link is:
which does't work , so I tried this:
'my_module_link' => $this->context->link->getModuleLink('mymodule', 'display.php')
and the real link change on this:
which is better but still does not work, so I manually change link
it is working, so the problem is in the function - getModuleLink or what? The functions get wrong folder name of the module. it returns mainfolder/module/mymodule/display, but it should be mainfolder/modules/mymodule/display.php
How I can change a getModuleLink function to work properly ?
Thanx
 
:)
so I change the function and it's working:
public function hookDisplayLeftColumn($params)
{
  $this->context->smarty->assign(
      array(
          'my_module_name' => Configuration::get('MYMODULE_NAME'),
          'my_module_link' => $this->_path.('display.php')
          //'my_module_link' => $this->context->link->getModuleLink('batfindmodule', 'display.php')
      )
 
:(
But to follow the tutorial it is not ok, it is still do not work.
Any help ? :)
Thanx
Edited by benbensk (see edit history)
Link to comment
Share on other sites

 

See this:

 

I follow the tutorial ( http://doc.prestashop.com/display/PS15/Creating+a+PrestaShop+module#CreatingaPrestaShopmodule-Technicalprinciplesbehindamodule )

too and:

I make this:

public function hookDisplayLeftColumn($params)
{
  $this->context->smarty->assign(
      array(
          'my_module_name' => Configuration::get('MYMODULE_NAME'),
          'my_module_link' => $this->context->link->getModuleLink('mymodule', 'display')
.....................
and the real link is:
which does't work , so I tried this:
'my_module_link' => $this->context->link->getModuleLink('mymodule', 'display.php')
and the real link change on this:
which is better but still does not work, so I manually change link
it is working, so the problem is in the function - getModuleLink or what? The functions get wrong folder name of the module. it returns mainfolder/module/mymodule/display, but it should be mainfolder/modules/mymodule/display.php
How I can change a getModuleLink function to work properly ?
Thanx
 
:)
so I change the function and it's working:
public function hookDisplayLeftColumn($params)

{

  $this->context->smarty->assign(

      array(

          'my_module_name' => Configuration::get('MYMODULE_NAME'),

          'my_module_link' => $this->_path.('display.php')

          //'my_module_link' => $this->context->link->getModuleLink('batfindmodule', 'display.php')

      )

 

Link to comment
Share on other sites

  • 4 months later...

Ok, solved.

There is an error in the official guide, where it says

 Let's create the display.php file that it targets, with a minimal content, and put it in the module's root folder.

If you put display.php in the module's root folder, you will have "page not found" error like me. After some rows, the guide says:

Let's explore display.php, our first PrestaShop front-end controller, stored in the /controllers/front folder of the module's main folder:

If you put display.php in /controllers/front, this will work!

Maybe that is a section of the old version (1.4) of the guide that nobody has removed. Furthermore, it's not specified where I should put the template file, but trying, I found that it has to be put in /views/templates/front

It would be good to modify the guide to teach the right steps <_<

Thanks anyway for help!

 

Wow, thank you, it was killing me!

Link to comment
Share on other sites

  • 2 months later...

Ok, solved.

There is an error in the official guide, where it says

 Let's create the display.php file that it targets, with a minimal content, and put it in the module's root folder.

If you put display.php in the module's root folder, you will have "page not found" error like me. After some rows, the guide says:

Let's explore display.php, our first PrestaShop front-end controller, stored in the /controllers/front folder of the module's main folder:

If you put display.php in /controllers/front, this will work!

Maybe that is a section of the old version (1.4) of the guide that nobody has removed. Furthermore, it's not specified where I should put the template file, but trying, I found that it has to be put in /views/templates/front

It would be good to modify the guide to teach the right steps <_<

Thanks anyway for help!

Thanks allot you saved me 

  • Like 1
Link to comment
Share on other sites

  • 5 months later...
  • 3 years later...

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...