Jump to content

Calling a controller's method/action/function from an url


dollarsound

Recommended Posts

Im a newbie and i can't find the answer neither googling nor testing. 

My doubt is let's say im creating a module with this methods:

 

Class testmoduleAllproductsModuleFrontController extends ModuleFrontController

 

{

 public function init()

{

    parent::init();

}

 

public function helloworld(){

}

}

 

Can i call helloworld method of this class from a url? I mean like codeigniter you can call like /controller/action/params/, thad would be /module/testmodule/Allproducts/helloworld  or like index.php?fc=module&module=testmodule&controller=AllProducts&action=helloworld? Or everything has to happen inside init()?

 

Thanks
Link to comment
Share on other sites

Thanks Vekia, but what i want to achive is:

 

Class testmoduleAllproductsModuleFrontController extends ModuleFrontController
 
{
 public function init()
{
    parent::init();
}
 
public function helloworld(){
    generate an output
}
public function buyworld(){
    generate an action
}
}
 
I would like to know if it's possible in presashop to call one of these public methods directly from an url.
as you can do in ror or in codeigniter not from inside the class. I dont know if im explaining myself right.
Link to comment
Share on other sites

  • 9 months later...
  • 9 months later...
  • 6 months later...

Hi,

I am using supershop theme and want to customize order module. I want to list invoice of particular product on the same page where it shows success message for order confirmation. Please suggest how can I achieve this??

Link to comment
Share on other sites

  • 10 months later...
example: yoursite.com/test?n1=22&n2=5
 in your controller 
class TestControllerCore extends FrontController
{

public function initContent()
{
parent::initContent();


if (Tools::getValue('n1')&&Tools::getValue('n2')){
 
            $n1=Tools::getValue('n1');
            $n2=Tools::getValue('n2');
            $res=$this->add($n1,$n2);
            $this->context->smarty->assign(array('res' => $res));
            }
$this->setTemplate(_PS_THEME_DIR_.'your_template.tpl'); }

public function add($n1,$n2){
          
          return $n1+$n2;
 
    }
}
your template.tpl
<center>
{$res}
</center>
$res=27

 

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