5

I got a package that contains few extensions. I want to redirect to my custom view once the package installation is fully complete.

I thought of trying via installer script using the postflight method as below.

public function postflight($route, JAdapterInstance $adapter){
    $app = JFactory::getApplication();
    $app->enqueueMessage('Post Installation... ');

    $app->redirect('index.php?option=com_mycomponent&view=install');
}

Problem: It is like hijacking the installer in half way by redirect to a different view. Because of this the post installer processes like updating the update server, post cleanup steps are not fully complete...

I tweaked the postflight code a little bit as below using javascript redirect.

public function postflight($route, JAdapterInstance $adapter){
    $jurl = JURI::base();
    $app = JFactory::getApplication();
    $app->enqueueMessage('Redirect to complete the Installation process... <script>window.location.href="'.$jurl.'index.php?option=com_mycomponent&view=install";</script>');
}

It looks like its working great... The redirect happens only after the complete installation of the package.

Need some expert advice here is there any decent way to achieve the same...

2

many developers including me use postflight to finalize installation, such as put my update server into database and update download id and other stuff.

After all, i will try to display a whole "html template" with installation complete message + few buttons for creating basic module by one click etc.

So technically, a postflight method is not for installation, it's for cleaning and other stuff which can be skipped.

I will advice you a lil' bit, not many people will like redirect automatically after installation, but decision is on your shoulders ; )

cheers!

  • I second that. In my components, I use postflight function as well and simply display a summary of what my script did and then a button that will redirect the customer to the component. Make sure you filter the actions so it will offer the redirect only on install or update but not on delete. (if ($route=='install' || $route=='update')) {} – Jeremy Mar 3 '17 at 22:09
1

According to this reference for custom component's installer script, couldn't just work with this code?

function install($parent){
        // $parent is the class calling this method
        $parent->getParent()->setRedirectURL('index.php?option=com_helloworld');
}

This should redirect after installation is complete.

Update: I've tested it in one of my components and it works

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.