Jump to content

Friendly URL for ModuleFrontController


carbotex

Recommended Posts

Hi,

 

I'm using Prestashop 1.6 and am trying to create a custom module with custom frontcontroller. I was able to dig around the forum to get it working, however I can't figure out how to create a friendly URL. Currently I have to use this format to access my controller

index.php?fc=module&module=test&controller=display

Is there a way to create friendly-url to something like the following:

/module-test-display

I went to the BO, under SEO and friendly URL, I can't see the page that I created with my custom module. How do I make the my custom module page appear in here?

 

 

Thanks,

 

-wa

Link to comment
Share on other sites

it should extend other class

class YourModuleNameControllerNameModuleFrontController extends ModuleFrontController{

}


 

 

Is there a way to create friendly-url to something like the following:

it is, under preferences > seo & urls add your new controller and generate friendly-url for it 

Link to comment
Share on other sites

it should extend other class

class YourModuleNameControllerNameModuleFrontController extends ModuleFrontController{

}

it is, under preferences > seo & urls add your new controller and generate friendly-url for it 

 

I'm using ModuleFrontController, I can access my module with this path. Note fc parameter has to be the last one, otherwise it will not work.

index.php?controller=sampah&module=thxslide&fc=module    <== Works

index.php?fc=module&controller=sampah&module=thxslide    <== 404

How do I add my new controller in order for me to generate friendly-url? When I click the Page dropdown, under the Module Pages section, I do not see my controller?

 

Below is what I have so far, did I miss anything?

 

/modules/thxslide/thxslide.php

<?php
if (!defined('_PS_VERSION_'))
  exit;
 
class ThxSlide extends Module
{
  public function __construct()
  {
    $this->name = 'thxslide';
    $this->tab = 'front_office_features';
    $this->version = '1.0.0';
    $this->author = 'Author';
    $this->need_instance = 0;
    $this->ps_versions_compliancy = array('min' => '1.6', 'max' => _PS_VERSION_); 

    $this->controllers = array('sampah');
    $this->bootstrap = true;
 
    parent::__construct();
 
    $this->displayName = $this->l('THX slide');
    $this->description = $this->l('Description of my module.');
 
    $this->confirmUninstall = $this->l('Are you sure you want to uninstall?');
 
    if (!Configuration::get('thxslide'))      
      $this->warning = $this->l('No name provided');
  }
}

/modules/thxslide/controllers/front/sampah.php

<?php

class ThxSlideSampahModuleFrontController extends ModuleFrontController
{
  
  public $php_self = "Sampah";  


  public function __construct()
  {
    parent::__construct();
    $this->context = Context::getContext();
  }

  /**
   * Initialize sampah controller
   */

  public function init()
  {
    parent::init();
    $this->display_column_left = false; 
    $this->display_column_right = false; 
  }

  /**
   * Set default media for this controller
   */
  public function setMedia()
  {
    parent::setMedia();
    $this->addJS(_THEME_JS_DIR_.'sampah.js');

    $this->addCSS(_THEME_CSS_DIR_.'sampah.css');
  }


  public function initContent()
  {
    parent::initContent();
    
    $this->context->smarty->assign(array(
      'path' => 'sampah',
    ));

    $this->setTemplate('sampah.tpl');
  }
}

/modules/thxslide/views/templates/front/sampah.tpl

<h2>Sampah Controller</h2>
Edited by carbotex (see edit history)
Link to comment
Share on other sites

×
×
  • Create New...