0

나는 컨트롤러라는 이름의 abandonedCarts을 만들어 :Prestashop 모듈 개발 - 모듈 설치시 컨트롤러 initMethod를 어떻게 호출 할 수 있습니까? 컨트롤러/앞

store_debug 단지 (단지 확인 용) DB를 뭔가에 기록하는 기능입니다
class <moduleName>AbandonedCartsModuleFrontController extends ModuleFrontController 
{ 

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


public function initContent() 
{ 
    parent::initContent(); 
    $this->store_debug('Controller - init'); 
} 

} 

. 덕분에 여기에 나는이 방법

site/index.php?fc=module&module=olyo&controller=abandonedCarts 

에 URL에서 컨트롤러를 호출 할 때 구조와 초기화 방법 호출되고 있다는 것을 알고 있지만, 내가 필요한 것은 모듈이 설치 될 때 호출되는 컨트롤러 (또는 처음 시작). 주 파일에서

나는 또한 생성자에서이 줄을 넣어 :

$this->controllers = array('abandonedCarts'); 

을하지만 나는 심지어

+0

어떤 prestashop 버전입니까? – sarcom

+0

모듈 설치시 init 메소드를 호출해야하는 이유는 무엇입니까? – shagshag

+0

@sarcom 버전은 1.6입니다. – frabis

답변

1

컨트롤러를 포함하고 단지 같은 객체 메소드를 호출 할 수 있습니다 필요가 확실하지 않다 다음 :

<?php 
class MyModule extends Module { 

    public install(){ 
    $file = _PS_MODULE_DIR_.'/'.$this->name.'/controllers/front/default.php'; 
    require_once $file; 
    $obj = new ObjectController(); 
    $obj->my_super_method(); 
    return true; 
    } 
} 

컨트롤러 매개 변수는 필요하지 않습니다. 현재 PrestaShop 버전의 발전기에 기본적으로 포함 무엇에 집중해야한다

모듈 :

<?php 
class MyModule extends Module { 
    public install(){ 
    $result = parent::install(); 
    if ($result) { 
     $this->doStuff(); 
    } 
    return $result; 
    } 

    public function doStuff() { 
    // do stuff 
    } 
} 

컨트롤러 당신은 관리자 컨텍스트에서을 FrontController의 인스턴스를 안 https://validator.prestashop.com/

+0

백 오피스에서 FrontController의 initContent를 초기화하고 호출하면 부작용이 발생할 수 있습니다. 예를 들어 DisplayHeader는 https://github.com/PrestaShop/PrestaShop/blob/1328a2876a955eab1a4edd34c4976eb36a8983db/classes/controller/FrontController.php#L532라고도합니다. – shagshag

+0

당신이 원하는 것을 캡슐화하는 또 다른 하위 함수를 직접 사용하지 않는 이유는 무엇입니까? 그것을 컨트롤러와 모듈 안에 넣으시겠습니까? –

+0

@MattLoye 당신의 솔루션을 시도했지만 뭔가 이상한 일이 일어난다. 모듈 install() 메소드에서 나는 어떤 메소드도 호출하지 않고 컨트롤러를 인스턴스화했다. 컨트롤러에서는 아무것도하지 않지만, 백 오피스는 상점 사이트에서 나를 리디렉션합니다. – frabis

0

, 여기에 해결 방법입니다

<?php 
class <moduleName>AbandonedCartsModuleFrontController extends ModuleFrontController 
{ 
    public function initContent() 
    { 
     parent::initContent(); 
     $this->module->doStuff(); 
    } 
}