Permalink
Browse files

Refactored to use url() view helper for generating all links

  • Loading branch information...
1 parent b77649d commit c366c06d836db9e2fde77b94c86c75660cd22204 @weierophinney weierophinney committed with weierophinney Sep 27, 2008
@@ -236,8 +236,16 @@ public function getModel()
*/
public function getForm()
{
- $form = $this->getModel()->getForm();
- $form->setAction('/paste/save')
+ $form = $this->getModel()->getForm();
+ $action = $this->view->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'save',
+ ),
+ 'default',
+ true
+ );
+ $form->setAction($action)
->setMethod('post');
return $form;
}
@@ -250,7 +258,16 @@ public function getForm()
*/
public function getFollowupForm($id)
{
- $form = $this->getForm();
+ $form = $this->getForm();
+ $action = $this->view->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'save-followup',
+ 'id' => $id,
+ ),
+ 'default',
+ true
+ );
$form->addElement('hidden', 'parent', array(
'required' => true,
'validators' => array(
@@ -259,7 +276,7 @@ public function getFollowupForm($id)
))
->setName('followupform')
->setElementsBelongTo('followupform')
- ->setAction('/paste/save-followup/id/' . $id);
+ ->setAction($action);
$form->save->setDijitParam('onClick', 'paste.main.followupPasteButton');
return $form;
}
@@ -0,0 +1,33 @@
+<?php
+/**
+ * Helper for retrieving base URL
+ *
+ * @uses Zend_View_Helper_Abstract
+ * @package Paste
+ * @author Matthew Weier O'Phinney <matthew@weierophinney.net>
+ * @copyright Copyright (C) 2008 - Present, Matthew Weier O'Phinney
+ * @license New BSD {@link http://framework.zend.com/license/new-bsd}
+ * @version $Id: $
+ */
+class Zend_View_Helper_BaseUrl extends Zend_View_Helper_Abstract
+{
+ /**
+ * @var string
+ */
+ protected $_baseUrl;
+
+ /**
+ * Return base URL of application
+ *
+ * @return string
+ */
+ public function baseUrl()
+ {
+ if (null === $this->_baseUrl) {
+ $request = Zend_Controller_Front::getInstance()->getRequest();
+ $this->_baseUrl = $request->getBaseUrl();
+ }
+
+ return $this->_baseUrl;
+ }
+}
@@ -18,6 +18,13 @@
</p>
<p class="new-paste">
- <a href="/paste/new">Create a new paste.</a>
+ <a href="<?= $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'new',
+ ),
+ 'default',
+ true
+ ) ?>">Create a new paste.</a>
</p>
<?= $this->contentPane()->captureEnd('about') ?>
@@ -22,14 +22,30 @@
</p>
<? if (!empty($this->paste['parent'])): ?>
<p class="parent">
- <a href="/paste/display/id/<?= $this->paste['parent'] ?>">Parent paste (<?= $this->paste['parent'] ?>)</a>
+ <a href="<?= $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'display',
+ 'id' => $this->paste['parent'],
+ ),
+ 'default',
+ true
+ ) ?>">Parent paste (<?= $this->paste['parent'] ?>)</a>
</p>
<? endif ?>
<? if (!empty($this->paste['children'])): ?>
<p class="children">Child pastes:</p>
<ul class="children">
<? foreach ($this->paste['children'] as $child): ?>
- <li><a href="/paste/display/id/<?= $child ?>"><?= $child ?></a></li>
+ <li><a href="<?= $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'display',
+ 'id' => $child,
+ ),
+ 'default',
+ true
+ ) ?>"><?= $child ?></a></li>
<? endforeach ?>
</ul>
<? endif ?>
@@ -1,4 +1,17 @@
-<? $this->contentPane()->captureStart('followup', array('title' => 'Followup', 'class' => 'tab', 'href' => '/paste/followup/id/' . $this->id . '/format/ajax', 'parseOnLoad' => true)) ?>
+<? $this->contentPane()->captureStart('followup', array(
+ 'title' => 'Followup',
+ 'class' => 'tab',
+ 'href' => $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'followup',
+ 'id' => $this->id,
+ 'format' => 'ajax',
+ ),
+ 'default',
+ true
+ ),
+ 'parseOnLoad' => true)) ?>
<script type="dojo/connect" event="onLoad">
dojo.connect(dojo.byId('followupform'), 'onsubmit', function () {
dojo.byId('followupform-code').value = dijit.byId('followupform-codeEditor').getValue(false);
@@ -1,7 +1,28 @@
<ul id="paste-nav">
<? if (!isset($this->message)): ?>
- <li><a href="/paste/followup/id/<?= $this->id ?>">Followup</a></li>
+ <li><a href="<?= $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'followup',
+ 'id' => $this->id,
+ ),
+ 'default',
+ true
+ )?>">Followup</a></li>
<? endif ?>
- <li><a href="/paste/new">New Paste</a></li>
- <li><a href="/paste">About</a></li>
+ <li><a href="<?= $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'new',
+ ),
+ 'default',
+ true
+ ) ?>">New Paste</a></li>
+ <li><a href="<?= $this->url(
+ array(
+ 'controller' => 'paste',
+ ),
+ 'default',
+ true
+ ) ?>">About</a></li>
</ul>
@@ -1,4 +1,16 @@
-<? $this->contentPane()->captureStart('new-paste', array('title' => 'New Paste', 'class' => 'tab', 'href' => '/paste/new/format/ajax', 'parseOnLoad' => true)) ?>
+<? $this->contentPane()->captureStart('new-paste', array(
+ 'title' => 'New Paste',
+ 'class' => 'tab',
+ 'href' => $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'new',
+ 'format' => 'ajax',
+ ),
+ 'default',
+ true
+ ),
+ 'parseOnLoad' => true)) ?>
<script type="dojo/connect" event="onLoad">
dojo.connect(dojo.byId('pasteform'), 'onsubmit', function () {
dojo.byId('pasteform-code').value = dijit.byId('pasteform-codeEditor').getValue(false);
@@ -1,18 +1,26 @@
<?
Zend_Dojo_View_Helper_Dojo::setUseDeclarative();
-$this->dojo()->addStylesheet('/js/dojox/grid/_grid/tundraGrid.css')
+$this->dojo()->addStylesheet($this->baseUrl() . '/js/dojox/grid/_grid/tundraGrid.css')
->requireModule('dojox.data.QueryReadStore')
->requireModule('dojox.grid.Grid');
?>
<span dojoType="dojox.data.QueryReadStore" jsId="activeStore"
- url="/paste/active-data/format/ajax"></span>
+ url="<?= $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'active-data',
+ 'format' => 'ajax',
+ ),
+ 'default',
+ true
+ ) ?>"></span>
<span dojoType="dojox.grid.data.DojoData" jsId="activeModel"
store="activeStore" rowsPerPage="30"></span>
<table id="activePastes" dojoType="dojox.grid.Grid" model="activeModel"
clientSort="false" query="{ id: '*' }" delayScroll="true">
<script type="dojo/method" event="onSelected" args="inRowIndex">
var row = dijit.byId("activePastes").model.getRow(inRowIndex);
-location.href = "/paste/display/id/" + row.id;
+location.href = "<?= $this->baseUrl() ?>/paste/display/id/" + row.id;
</script>
<thead>
<tr>
@@ -2,7 +2,19 @@
<? $this->tabContainer()->captureStart('pastebin', array('class' => 'paste-tab')) ?>
<?= $this->render('paste/_about.phtml') ?>
<?= $this->render('paste/_new-paste.phtml') ?>
-<?= $this->contentPane('active', '', array('title' => 'Active Pastes', 'class' => 'tab', 'href' => '/paste/active/format/ajax', 'parseOnLoad' => true)) ?>
+<?= $this->contentPane('active', '', array(
+ 'title' => 'Active Pastes',
+ 'class' => 'tab',
+ 'href' => $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'active',
+ 'format' => 'ajax',
+ ),
+ 'default',
+ true
+ ),
+ 'parseOnLoad' => true)) ?>
<? $this->contentPane()->captureStart('paste', array('title' => $this->title, 'class' => 'tab', 'selected' => true)) ?>
<?= $this->render('paste/_nav.phtml') ?>
<?= $this->render('paste/_display.phtml') ?>
@@ -2,8 +2,33 @@
<? $this->tabContainer()->captureStart('pastebin', array('class' => 'paste-tab')) ?>
<?= $this->render('paste/_about.phtml') ?>
<?= $this->render('paste/_new-paste.phtml') ?>
-<?= $this->contentPane('active', '', array('title' => 'Active Pastes', 'class' => 'tab', 'href' => '/paste/active/format/ajax', 'parseOnLoad' => true)) ?>
-<?= $this->contentPane('paste', '', array('title' => $this->title, 'class' => 'tab', 'href' => '/paste/display/id/' . $this->id . '/format/ajax', 'parseOnLoad' => true)) ?>
+<?= $this->contentPane('active', '', array(
+ 'title' => 'Active Pastes',
+ 'class' => 'tab',
+ 'href' => $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'active',
+ 'format' => 'ajax',
+ ),
+ 'default',
+ true
+ ),
+ 'parseOnLoad' => true)) ?>
+<?= $this->contentPane('paste', '', array(
+ 'title' => $this->title,
+ 'class' => 'tab',
+ 'href' => $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'display',
+ 'id' => $this->id,
+ 'format' => 'ajax',
+ ),
+ 'default',
+ true
+ ),
+ 'parseOnLoad' => true)) ?>
<? $this->contentPane()->captureStart('followup', array('title' => 'Followup', 'class' => 'tab', 'selected' => true)) ?>
<? if (isset($this->message)): ?>
<h2>Error</h2>
@@ -2,5 +2,17 @@
<? $this->tabContainer()->captureStart('pastebin', array('class' => 'paste-tab')) ?>
<?= $this->render('paste/_about.phtml') ?>
<?= $this->render('paste/_new-paste.phtml') ?>
-<?= $this->contentPane('active', '', array('title' => 'Active Pastes', 'class' => 'tab', 'href' => '/paste/active/format/ajax', 'parseOnLoad' => true)) ?>
+<?= $this->contentPane('active', '', array(
+ 'title' => 'Active Pastes',
+ 'class' => 'tab',
+ 'href' => $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'active',
+ 'format' => 'ajax',
+ ),
+ 'default',
+ true
+ ),
+ 'parseOnLoad' => true)) ?>
<?= $this->tabContainer()->captureEnd('pastebin') ?>
@@ -4,5 +4,17 @@
<? $this->contentPane()->captureStart('new-paste', array('title' => 'New Paste', 'class' => 'tab', 'selected' => true)) ?>
<?= $this->form ?>
<?= $this->contentPane()->captureEnd('new-paste') ?>
-<?= $this->contentPane('active', '', array('title' => 'Active Pastes', 'class' => 'tab', 'href' => '/paste/active/format/ajax', 'parseOnLoad' => true)) ?>
+<?= $this->contentPane('active', '', array(
+ 'title' => 'Active Pastes',
+ 'class' => 'tab',
+ 'href' => $this->url(
+ array(
+ 'controller' => 'paste',
+ 'action' => 'active',
+ 'format' => 'ajax',
+ ),
+ 'default',
+ true
+ ),
+ 'parseOnLoad' => true)) ?>
<?= $this->tabContainer()->captureEnd('pastebin') ?>

0 comments on commit c366c06

Please sign in to comment.