My project links to an external form. Once that external form is submitted, the user is brought back to the ee site. I need to send the form a param (ie ?action=dev) to tell it which environment to return to. We currently have dev, client review, staging (excessive much?) and will eventually have the live site.

I don't want to have to remember to change these external links when updating. One of the links is a Low Variables var so I can't php strpos and it's not even letting me do an if statement on the value of site_url.

Does a plugin or extension exist that will help me out?

Thanks Amanda

  • 1
    To clarify, you're just looking for a way to create a link on the EE site to your external form that includes a GET variable for which environment to return to in the URL? Couldn't you just add another low variable that you set per environment and use that in the external link (i.e.: lv_environment with a value of dev or client, etc..)? – Romans-8---31-39 Jan 10 '14 at 17:15
  • In this case, yes, it's a param at the end of a link but really it could be anything. In this env, I want it to return aaa. In that env, I want it to return bbb. I don't see how another Low Var will help. I'd still need to change the var when I update from dev to staging, right? That's the same as I'm doing now. – Amanda Lutz Jan 10 '14 at 21:34

This is what the assign_to_config array in your main index.php file is for (assuming you're not using something like FocusLab Master Config, which makes multi-environment really easy). If you don't want to use that approach, the quick way is to just crack open your index.php file, scroll down to the bit where assign_to_config gets set, and create some global variables based on, say, the $_SERVER['HTTP_HOST'] var.

Here's a quick example using a switch statement to determine local/dev/live environment and setting some global variables accordingly (I use this as a quick and easy method for displaying draft content on the dev site):

switch($_SERVER["HTTP_HOST"]) { 
    case "dev.site.com" :
        $assign_to_config['global_vars']['gv_site'] = 'dev';
        $assign_to_config['global_vars']['gv_entry_statuses'] = 'open|Draft';
        $assign_to_config['site_url'] = "http://dev.site.com/"; // if you don't set this, it's taken from the database instead

    case "www.site.com" :
    case "site.com" :   
        $assign_to_config['global_vars']['gv_site'] = 'live';
        $assign_to_config['global_vars']['gv_entry_statuses'] = 'open';

    case "site.dev" :
    case "localhost" :
        $assign_to_config['global_vars']['gv_site'] = 'dev';
        $assign_to_config['global_vars']['gv_entry_statuses'] = 'open';
        $assign_to_config['site_url'] = "http://site.dev/";

You can then use {gv_site} anywhere in your templates.

| improve this answer | |

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.