Skip to content

Commit

Permalink
Adding convenience method for setting the allowed response types for …
Browse files Browse the repository at this point in the history
…a route. Adding parameter to base controller to set auto view discovering.
  • Loading branch information
mAu888 committed Apr 7, 2012
1 parent 947949b commit ef5433b
Show file tree
Hide file tree
Showing 2 changed files with 33 additions and 1 deletion.
10 changes: 9 additions & 1 deletion Zurv/Controller/Base.php
Expand Up @@ -39,6 +39,14 @@ class Base implements Controller {
*/
protected $_viewsPath = 'views/';

/**
* If the view adapter should be loaded based on the extension or specific
* headers send in the request or not.
*
* @var bool
*/
protected $_detectViewAdapter = true;

/**
* If this member variable is overwritten, this file will be used as the
* template instead of auto picking.
Expand Down Expand Up @@ -96,7 +104,7 @@ protected function _loadView($view) {
*/
protected function _initView() {
$adapter = null;
if($this->getRequest()->isAjaxRequest()) {
if($this->_detectViewAdapter && $this->getRequest()->isAjaxRequest()) {
$adapter = AdapterFactory::create(AdapterFactory::JSON);
}
else {
Expand Down
24 changes: 24 additions & 0 deletions Zurv/Router/Route.php
Expand Up @@ -2,6 +2,11 @@
namespace Zurv\Router;

class Route {
const GET = 'get';
const POST = 'post';
const PUT = 'put';
const DELETE = 'delete';

protected $_route = '';
protected $_controller = 'Index';
protected $_action = 'index';
Expand Down Expand Up @@ -65,6 +70,25 @@ public function getRequireXmlHttpRequest() {
return $this->_requireAjax;
}

public function setRequestTypes() {
$args = func_get_args();

$this->forGetRequest(false);
$this->forPostRequest(false);
$this->forPutRequest(false);
$this->forDeleteRequest(false);

foreach($args as $arg) {
switch($arg) {
case self::GET: $this->forGetRequest(true); break;
case self::POST: $this->forPostRequest(true); break;
case self::PUT: $this->forPutRequest(true); break;
case self::DELETE: $this->forDeleteRequest(true); break;
default: break;
}
}
}

public function forGetRequest($responds = true) {
$this->_get = $responds;
}
Expand Down

0 comments on commit ef5433b

Please sign in to comment.