2017-03-22 3 views
0

では見つかりません: /modules/mymodule/controllers/admin/myControlController.phpPrestaShopの、クラスはModuleAdminController :: getController私は、例えば、私が置かコントローラとのPrestaShopのモジュールを開発しようとしている

class MyControlController extends ModuleAdminController { 
public function __construct() {   
     $this->module = 'mymodule'; 
     $this->bootstrap = true; 
     $this->context = Context::getContext();  
     $token = Tools::getAdminTokenLite('AdminModules'); 
     $currentIndex='index.php?controller=AdminModules&token='.$token.'&configure=mymodule&tab_module=administration&module_name=mymodule'; 
     Tools::redirectAdmin($currentIndex); 
     parent::__construct();     
} 
public function showForm() { 
    die("hello"); 
}} 
(> ShowFormを - ModuleAdminController :: getController(「MyControlと」):

コントローラが、私はそれを呼び出す場合は、URLに http://myshop.com/adminxxx/index.php?controller=MyControl&token=9faf638aa961468c8563ffb030b3c4a8

を形成する(構築メソッドが呼ばれた)が、私はモジュールのメインクラスから、コントローラのメソッドにアクセスすることはできません動作します); 私は「クラスが見つかりません」というメッセージを受け取った

外部からコントロールにアクセスする正しい方法はありますか? ありがとう!

+0

申し訳ありませんが、なぜそれを実行します。ここでは

は働くことができ、コントローラの例ですか?あなたのモジュールにメソッドを作り、 'getContent()'メソッドを使って、あなたが望むメソッドを呼び出すことができます。 – sarcom

+0

あなたは何を意味しているのでしょうか?申し訳ありません、私のモジュールファイルのgetContentメソッドからアクセスできません。/modules/mymodule/controllers/admin/ –

+0

あなたのモジュールで 'showForm()'メソッドを直接作ることができます管理者コントローラーを使用してください:) – sarcom

答えて

0

フォームに関係するものを表示する場合は、renderForm()を使用する必要があります。 あなたはparent :: showForm();を試してください。または$ this-> showForm();

require_once _PS_MODULE_DIR_.'modulename/models/ModuleNameLog.php'; 
require_once _PS_MODULE_DIR_.'modulename/modulename.php'; 

class AdminModuleNameLogController extends ModuleAdminController 
{ 
    protected $_defaultOrderBy = 'id_modulenamelog'; 
    protected $_defaultOrderWay = 'DESC'; 

    public function __construct() 
    { 
    $this->table = 'modulenamelog'; 
    $this->className = 'ModuleNameLog'; 

    $this->context = Context::getContext(); 
    $this->lang = false; 
    $this->bootstrap = true; 
    $this->actions_available = array(); 
    $this->actions = array(); 
    $this->show_toolbar = false; 
    $this->toolbar_btn['new'] = array(); 
    $this->tabAccess['add'] = '0'; 
    $this->allow_export = true; 
    $this->requiredDatabase = true; 
    $this->page_header_toolbar_title = $this->l('Example Module Name logs'); 

    $this->_select = 'SUM(a.quantity) as total_quantity'; 
    $this->_group = ' GROUP BY a.id_product, a.id_product_attribute '; 

    $this->fields_list = array(
     'id_product' => array(
      'title' => $this->l('Product'), 
      'align' => 'center', 
      'callback' => 'getProductName', 
     ), 
     'id_product_attribute' => array(
      'title' => $this->l('Combination'), 
      'align' => 'center', 
      'callback' => 'getAttributeName', 
     ), 
     'total_quantity' => array(
      'title' => $this->l('Total Quantity'), 
      'align' => 'center', 
     ), 
    ); 

    $this->mod = new ModuleName(); 
    $this->mod->cleanLogs(); 

    $this->context = Context::getContext(); 

    parent::__construct(); 
} 

public function getProductName($id) 
{ 
    if (!empty($id)) { 
     $product = new Product($id, true, $this->context->cookie->id_lang); 

     return $product->name; 
    } 
} 
public function getAttributeName($id) 
{ 
    if (!empty($id)) { 
     $combination = new Combination($id); 
     $names = $combination->getAttributesName($this->context->cookie->id_lang); 
     $str = array(); 

     if (!empty($names)) { 
      foreach ($names as $value) { 
       $str[] = $value['name']; 
      } 
     } 

     return implode(' - ', $str); 
    } else { 
     return '-'; 
    } 
} 

public function postProcess() 
{ 
    if (Tools::isSubmit('purge_id')) { 

     // Do something here 
     $id = (int) Tools::getValue('purge_id'); 


     Tools::redirectAdmin(self::$currentIndex.'&token='.Tools::getAdminTokenLite('AdminModuleNameLog').'&conf=4'); 

    } 

    parent::postProcess(); 
} 

public function renderList() 
{ 
    $carts = Db::getInstance()->executeS('SELECT ct.*, cs.`firstname`, cs.`lastname` FROM '._DB_PREFIX_.'cart ct LEFT JOIN '._DB_PREFIX_.'customer cs ON ct.id_customer = cs.id_customer WHERE 1 ORDER BY id_cart DESC LIMIT 0,2000'); 

    $tpl = $this->context->smarty->createTemplate(_PS_MODULE_DIR_.'modulename/views/templates/admin/preform.tpl'); 

    $tpl->assign(array(
     'carts' => $carts, 
    )); 

    $html = $tpl->fetch(); 

    return $html.parent::renderList(); 
} 

public function renderForm() 
{ 
    if (!$this->loadObject(true)) { 
     return; 
    } 

    $obj = $this->loadObject(true); 

    if (isset($obj->id)) { 
     $this->display = 'edit'; 
    } else { 
     $this->display = 'add'; 
    } 

    $array_submit = array(
     array(
      'type' => 'select', 
      'label' => $this->l('Cart :'), 
      'name' => 'id_cart', 
      'options' => array(
       'query' => Db::getInstance()->executeS('SELECT * FROM '._DB_PREFIX_.'cart WHERE id_cart > 0 ORDER BY id_cart DESC LIMIT 0,500'), 
       'id' => 'id_cart', 
       'name' => 'id_cart', 
      ), 
     ), 
     array(
      'type' => 'text', 
      'label' => $this->l('Quantity translation here'), 
      'hint' => $this->l('Description and translation here'), 
      'name' => 'quantity', 
     ), 
    ); 

    $this->fields_form[0]['form'] = array(
     'tinymce' => false, 
     'legend' => array(
      'title' => $this->l('Form title'), 
     ), 
     'input' => $array_submit, 
     'submit' => array(
      'title' => $this->l('Save'), 
      'class' => 'btn btn-default', 
     ), 
    ); 

    $this->multiple_fieldsets = true; 

    return parent::renderForm(); 
} 
} 
関連する問題