0
votes

I have problem with my first module.

I create a module modules/fashion/fashion.php

  <?php

 class Fashion extends Module
{
function __construct()
{
    $this->name = 'fashion';
    $this->tab = 'administration';
    $this->version = 1.0;
            $this->bootstrap = true;
    parent::__construct(); // The parent construct is required for translations

    $this->page = basename(__FILE__, '.php');
    $this->displayName = $this->l('Block Fashion');
    $this->description = $this->l('Add a fashion block');
}

        public function install()
    {
        if (!parent::install() ||
                !$this->registerHook('header')) {
            return false;
        }
        if (Shop::isFeatureActive()) {
            Shop::setContext(Shop::CONTEXT_ALL);
        }

        $tab = new Tab();
        $tab->active = 1;
        $tab->class_name = 'AdminFashionController';
        $tab->name = array();
        foreach (Language::getLanguages(true) as $lang) {
        $tab->name[$lang['id_lang']] = "Fashion";
        }
        $tab->id_parent = (int)Tab::getIdFromClassName('Fashion');
        $tab->module = $this->name;
        return $tab->add();

    }
    public function uninstall()
    {
    // Uninstall Tabs
    $tab = new Tab((int)Tab::getIdFromClassName('Fashion'));
    $tab->delete();

    // Uninstall Module
    if (!parent::uninstall())
        return false;
    }
/**
* Returns module content
*
* @param array $params Parameters
* @return string Content
*/


}

?>

What is more i create modules/fashion/controller/admin/FashionAdminController.php

<?php
class FashionAdminController extends ModuleAdminController
{
public function initContent(){
    parent::initContent();
    $this->setTemplate('fashion.tpl');
}
}
?>

And modules/fashion/views/templates/admin/fashion.tpl

<!-- Block mymodule -->
 <div id="mymodule_block_left" class="block">
 <h4>Welcome!</h4>
 <div class="block_content">
   <p>Hello,
   {if isset($my_module_name) && $my_module_name}
       {$my_module_name}
   {else}
       World
   {/if}
   !       
</p>   
<ul>
  <li><a href="{$my_module_link}" title="Click this link">Click me!</a></li>
</ul>
</div>
</div>
<!-- /Block mymodule -->

So, when i click in my Admin Panel the link Fashion the shows "The page is no found" Why? What i did wrong? Can someone help me?

1

1 Answers

0
votes

At first, check if the menu(tab) has been created in the backend or not.

I also think that the admin controller name should start with ADMIN : AdminFashionController and use this name for tab class :

$tab->class_name = 'AdminFashion';

Sample from default module:

public function installTab()
{
    $tab = new Tab();
    $tab->active = 1;
    $tab->class_name = "AdminLinkWidget";
    $tab->name = array();
    foreach (Language::getLanguages(true) as $lang) {
        $tab->name[$lang['id_lang']] = "Link Widget";
    }
    $tab->id_parent = (int)Tab::getIdFromClassName('AdminParentThemes');
    $tab->module = $this->name;
    return $tab->add();
}

You have to add "active" and remove "position"(is automatic)