Jump to content

Adding a new page, controller issue


Rhobur

Recommended Posts

Hi,

I have read all I could find about creating a new page in PS 1.5+.

Unfortunately I cannot make it work.

I am trying to create a new page following this thread, http://www.prestasho...ost__p__1170809, too but i get an error "The website encountered an error while retrieving http://www.caprice-s...certificatcadou. It may be down for maintenance or configured incorrectly."

Here is what I did:

1. Created FrontController.php to override/classes/controller/front

<?php
class FrontController extends FrontControllerCore
{
public function init() {
			parent::init();
 $this--->context->smarty->assign('currentController', get_class($this));
}
}

2. Created certificatcadou.php in / :

require(dirname(__FILE__).'/config/config.inc.php');
Tools::displayFileAsDeprecated();
Tools::redirect('index.php?controller=certificatcadou'.($_REQUEST ? '&'.http_build_query($_REQUEST, '', '&') : ''), __PS_BASE_URI__, null, 'HTTP/1.1 301 Moved Permanently');

3. Created certificatcadou.tpl in /themes/mytheme :

{include file="$tpl_dir./breadcrumb.tpl"}
{include file="$tpl_dir./errors.tpl"}
<h1>Testpage</h1>
controller: {$CertificatCadouController}

4. Created CertificatCadouController.php in /controllers/front/ :

<?php
class CertificatCadouControllerCore extends FrontController
{
public $php_self = 'certificatcadou';

public function initContent()
{
 parent::initContent();
 $this->setTemplate(_PS_THEME_DIR_.'certificatcadou.tpl');
}
}

5. Added In PS admin > Prefrences > SEO & URLs

Add new > Page = certificatcadou , Title = Certificat Cadou , Friendly URL = certificatcadou

 

Still no luck!!

Can you advise what could be wrong?

Robert

 

Edit: enabling error messaging I have found :

Fatal error: Class 'CertificatCadouController' not found in /home/sites/caprice-shop.ro/public_html/classes/controller/Controller.php on line 128

What is this? Shouls I move the new Controller file to /classes/controller/?

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

  • 2 months later...

I would first remove the FrontController override. It does not seem necessary.

In your theme template file, remove the following, the variable $CertificatCadouController does not exist.

 

Also, I noticed the link to the new page does not match the name of the page (icertificatcadou != certificatcadou)

 

Everything else looks right

Link to comment
Share on other sites

  • 5 months later...

Sorry for replying to an old thread, but this just happened to me.

Here's how I solved it.

 

In file /classes/Dispatcher.php around line 251 you'll find a switch case statement:

case self::FC_FRONT :
  //Some code here
break;

Just above the break; insert the following:

if(!class_exists($controller_class))
{
    include_once(_PS_FRONT_CONTROLLER_DIR_."/".$controller_class.".php");
}

So it looks something like this:

case self::FC_FRONT :
  //Some code here
  if(!class_exists($controller_class))
  {
      include_once(_PS_FRONT_CONTROLLER_DIR_."/".$controller_class.".php");
  }
break;

What this will do is include the class (if it hasn't been included yet), getting rid of the "Class X not found" error.

Link to comment
Share on other sites

  • 2 months later...
  • 1 year 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...