Jump to content

Admin Controller Ineheritence&Overriding problem


Mohammad Nazrul

Recommended Posts

Hello Experts,

I am module developer. For one of module development I have to use/inheritance  ModuleAdminController.

 

The problem happen when I am going to use OOP's override technique for a method, it first execute parent method's statement then child statement! although I am not using parent::method() & I want no execution of parent's method that is completely override.

 

Example :

Class 1:  Controller

-----------------------

abstract public function setMedia();

 

Class 2: AdminController inherit Class 1.

---------------------------------------------------

public function setMedia()
    {            
        $this->addCSS(_PS_CSS_DIR_.'admin.css', 'all');
        $admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_);
        $admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath);
        $this->addCSS(__PS_BASE_URI__.$admin_webpath.'/themes/'.$this->bo_theme.'/css/admin.css', 'all');
        if ($this->context->language->is_rtl)
            $this->addCSS(_THEME_CSS_DIR_.'rtl.css');

        $this->addJquery();
        $this->addjQueryPlugin(array('cluetip', 'hoverIntent', 'scrollTo', 'alerts', 'chosen'));

        $this->addJS(array(
            _PS_JS_DIR_.'admin.js',
            _PS_JS_DIR_.'toggle.js',
            _PS_JS_DIR_.'tools.js',
            _PS_JS_DIR_.'ajax.js',
            _PS_JS_DIR_.'toolbar.js'
        ));

        if (!Tools::getValue('submitFormAjax'))
        {
            $this->addJs(_PS_JS_DIR_.'notifications.js');
            if (Configuration::get('PS_HELPBOX'))
                $this->addJS(_PS_JS_DIR_.'helpAccess.js');
        }                
        // Execute Hook AdminController SetMedia
        Hook::exec('actionAdminControllerSetMedia', array());
    }

Class 3: ModuleAdminControllerCore inherit Class2.

-------------------------------------------------------------

Nothing

Class 4: MyBaseController inherit Class 3

------------------------------------------------------

public function setMedia() {
        //No parent::setMedia() has been used.
        My Coding.......................................
        Hook::exec('actionAdminControllerSetMedia', array());
    }

Class 4 : MyModuleAdminController inherit from class 4 : This will be actually used as customized admin controller.

 

Now when run MyModuleAdminController Class 2 setMedia() first execute then class 4 execute runs, that means mess up with other media, which I don't want.

 

Please let me know if need more info

Thanks in advance

Edited by Mohammad Nazrul (see edit history)
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...