From 941fa95eecd71d23aaad5dea946e4f6ab1ec2d4d Mon Sep 17 00:00:00 2001 From: Demian Katz <demian.katz@villanova.edu> Date: Mon, 25 Jun 2012 13:49:48 -0400 Subject: [PATCH] Finished IndexController -- it now forwards correctly. Note that this required loading the latest master copy of the ZF2 Forward plug-in; the official version distributed with beta4 was broken. --- module/VuFind/config/module.config.php | 3 +- .../src/VuFind/Controller/IndexController.php | 18 +++---- .../VuFind/Controller/SearchController.php | 54 +++++++++++++++++++ .../Zend/Mvc/Controller/Plugin/Forward.php | 17 ++---- 4 files changed, 68 insertions(+), 24 deletions(-) create mode 100644 module/VuFind/src/VuFind/Controller/SearchController.php diff --git a/module/VuFind/config/module.config.php b/module/VuFind/config/module.config.php index 310dbd8f91a..8f954f6a3fe 100644 --- a/module/VuFind/config/module.config.php +++ b/module/VuFind/config/module.config.php @@ -114,7 +114,8 @@ return array( ), 'controller' => array( 'classes' => array( - 'index' => 'VuFind\Controller\IndexController' + 'index' => 'VuFind\Controller\IndexController', + 'search' => 'VuFind\Controller\SearchController' ), ), 'view_manager' => array( diff --git a/module/VuFind/src/VuFind/Controller/IndexController.php b/module/VuFind/src/VuFind/Controller/IndexController.php index 3e1a794eec8..c3b179368bf 100644 --- a/module/VuFind/src/VuFind/Controller/IndexController.php +++ b/module/VuFind/src/VuFind/Controller/IndexController.php @@ -29,8 +29,7 @@ namespace VuFind\Controller; use VuFind\Config\Reader as ConfigReader, VuFind\Account\Manager as AccountManager, - Zend\Mvc\Controller\ActionController, - Zend\View\Model\ViewModel; + Zend\Mvc\Controller\ActionController; /** * Redirects the user to the appropriate default VuFind action. @@ -44,8 +43,8 @@ use VuFind\Config\Reader as ConfigReader, class IndexController extends ActionController { /** - * Determines what elements are displayed on the - * home page based on if the user is logged in. + * Determines what elements are displayed on the home page based on whether + * the user is logged in. * * @return void */ @@ -54,14 +53,11 @@ class IndexController extends ActionController $config = ConfigReader::getConfig(); $loggedInModule = isset($config->Site->defaultLoggedInModule) ? $config->Site->defaultLoggedInModule : 'MyResearch'; - $loggedInOpts = array('controller' => $loggedInModule, 'action' => 'Home'); $loggedOutModule = isset($config->Site->defaultModule) ? $config->Site->defaultModule : 'Search'; - $loggedOutOpts = array('controller' => $loggedOutModule, 'action' => 'Home'); - if (AccountManager::getInstance()->isLoggedIn()) { - return $this->forward()->dispatch('default', $loggedInOpts); - } else { - return $this->forward()->dispatch('default', $loggedOutOpts); - } + $module = AccountManager::getInstance()->isLoggedIn() + ? $loggedInModule : $loggedOutModule; + $options = array('action' => 'Home', 'controller' => $module); + return $this->forward()->dispatch($module, $options); } } diff --git a/module/VuFind/src/VuFind/Controller/SearchController.php b/module/VuFind/src/VuFind/Controller/SearchController.php new file mode 100644 index 00000000000..701997263f6 --- /dev/null +++ b/module/VuFind/src/VuFind/Controller/SearchController.php @@ -0,0 +1,54 @@ +<?php +/** + * Default Controller + * + * PHP version 5 + * + * Copyright (C) Villanova University 2010. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2, + * as published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + * + * @category VuFind2 + * @package Controller + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +namespace VuFind\Controller; + +use Zend\Mvc\Controller\ActionController; + +/** + * Redirects the user to the appropriate default VuFind action. + * + * @category VuFind2 + * @package Controller + * @author Demian Katz <demian.katz@villanova.edu> + * @license http://opensource.org/licenses/gpl-2.0.php GNU General Public License + * @link http://vufind.org Main Site + */ +class SearchController extends ActionController +{ + /** + * Home action + * + * @return void + */ + public function homeAction() + { + /* TODO: + $this->view->results = $this->getAdvancedFacets(); + */ + } +} diff --git a/vendor/ZF2/library/Zend/Mvc/Controller/Plugin/Forward.php b/vendor/ZF2/library/Zend/Mvc/Controller/Plugin/Forward.php index 04a72780cad..0165d1276bb 100644 --- a/vendor/ZF2/library/Zend/Mvc/Controller/Plugin/Forward.php +++ b/vendor/ZF2/library/Zend/Mvc/Controller/Plugin/Forward.php @@ -66,7 +66,7 @@ class Forward extends AbstractPlugin */ public function dispatch($name, array $params = null) { - $event = $this->getEvent(); + $event = clone($this->getEvent()); $locator = $this->getLocator(); $scoped = false; @@ -80,21 +80,18 @@ class Forward extends AbstractPlugin if (!$controller instanceof Dispatchable) { throw new Exception\DomainException('Can only forward to DispatchableInterface classes; class of type ' . get_class($controller) . ' received'); } + if ($controller instanceof InjectApplicationEventInterface) { + $controller->setEvent($event); + } if (!$scoped) { - if ($controller instanceof InjectApplicationEventInterface) { - $controller->setEvent($event); - } if ($controller instanceof ServiceLocatorAwareInterface) { $controller->setServiceLocator($locator); } } // Allow passing parameters to seed the RouteMatch with - $cachedMatches = false; if ($params) { - $matches = new RouteMatch($params); - $cachedMatches = $event->getRouteMatch(); - $event->setRouteMatch($matches); + $event->setRouteMatch(new RouteMatch($params)); } if ($this->numNestedForwards > $this->maxNestedForwards) { @@ -106,10 +103,6 @@ class Forward extends AbstractPlugin $this->numNestedForwards--; - if ($cachedMatches) { - $event->setRouteMatch($cachedMatches); - } - return $return; } -- GitLab