Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We're retiring the forums!

The SilverStripe forums have passed their heyday. They'll stick around, but will be read only. We'd encourage you to get involved in the community via the following channels instead:

Archive /

Our old forums are still available as a read-only archive.

Moderators: martimiz, Sean, Ed, biapar, Willr, Ingo

Extension: Developer Flush link


Go to End


1294 Views

Avatar
JGC

Community Member, 25 Posts

5 December 2008 at 6:36am

Edited: 05/12/2008 3:00pm

It's sort of an extension, anyway :)

What it does
Adds a link to the main menu of the CMS to enable/disable flush-mode (?flush=1) for developing.
- Says "Start Flush" or "Stop Flush" depending on whether you're in flush-mode
- Doesn't destroy any other URL parameters you're using
- Doesn't modify other links on page, so flush will reset to OFF when you follow non-AJAX links

Why?
I've only been using SS for a couple of weeks, but I'm already sick of typing in ?flush=1 to refresh the page :P Just wrote this and I'm posting it in case anyone else thinks it's a small but handy tool.

How?
Just add these two pieces of code into your site:

cms/code/LeftAndMain.php, line 294 of an unchanged LeftAndMain.php, or the line after '$linkingmode = "";' in 'public function MainMenu()' for changed files

##	DEVELOPER'S FLUSH LINK 1.2 - 3 lines here, 44 in mysite/_config.php
$urlQ = parse_url($_SERVER['REQUEST_URI']);
if (isset($urlQ['query'])) { if (strstr($urlQ['query'], 'flush=1') && ($menuItem->title == 'Start Flush' || $menuItem->title == 'Stop Flush')) { $linkingmode = "current"; } }

At the bottom of mysite/config.php, before the PHP close tag (if not using /mysite then put in whichever folder is relevant)

###
##	DEVELOPER'S FLUSH LINK 1.2 - 44 lines here, 3 in cms/code/LeftAndMain.php
##	Adds a 'Flush' link to the main menu - handy for developing!
##	Lets developers go to the toilet without leaving the keyboard [first and last toilet joke]
###

$url = parse_url($_SERVER['REQUEST_URI']);
$flushTitle = '';

# Is there a 'query' array element? If not, we can't be flushing
if (!isset($url['query']) || $url['query'] == '') { $url['query'] = '?flush=1'; $flushTitle = 'Start '; }
else
	{
	# Are we already flushing?
	if (strstr($url['query'], 'flush=1'))
		{
		# Update the Menu Title hint
		$flushTitle = 'Stop ';
		# Remove the flushes
		$url['query'] = str_replace('?flush=1', '', $url['query']);
		$url['query'] = str_replace('&flush=1', '', $url['query']);
		$url['query'] = str_replace('flush=1', '', $url['query']);
		# Check it doesn't now start with a &
		if (substr($url['query'], 0, 1) == '&') { $url['query'] = '?' . substr($url['query'], 1); }
		else if (substr($url['query'], 0, 1) != '?' && strlen($url['query']) > 0) { $url['query'] = '?' . $url['query']; }
		}
	else
		{
		# Not flushing
		if (strlen($url['query']) > 0)	{ $url['query'] = '?' . $url['query'] . '&flush=1'; }
		else							{ $url['query'] = '?flush=1'; }
		# Update the Menu Title hint
		$flushTitle = 'Start ';
		}
	}
$flushLink = implode($url);

# Add a divider, then the flush item
CMSMenu::add_link('X_FLUSH_DIVIDER', '|', '#', -1);
CMSMenu::add_link('LINK_FLUSH', $flushTitle . 'Flush', $flushLink, -2);

###
##	END OF DEVELOPER'S FLUSH LINK
###

Changelog
1.2 - Now highlights link on main menu if you're in flush-mode
1.1 - Whoops, posted the wrong version. Ah well, I guess it's an update, of sorts.
1.0 - Created