Commit: 298d323fa7b93e2ddb7bc7208a047b7dfab08e51

Author: gwoo | Date: 2010-01-25 15:00:04 -0800
adding by_field to LabView. Adding supprot for {name}.json to Plugins::view
diff --git a/config/routes.php b/config/routes.php index ed09841..c588c6a 100644 --- a/config/routes.php +++ b/config/routes.php @@ -7,15 +7,14 @@ */ use \lithium\http\Router; + Router::connect('/lab', array( 'plugin' => 'li3_lab', 'controller' => 'home', 'action' => 'index' )); -Router::connect('/lab/{:controller}/{:action}', array( - 'plugin' => 'li3_lab', 'controller' => 'plugins' +Router::connect('/lab/{:args}.json', array( + 'plugin' => 'li3_lab', 'controller' => 'plugins', 'action' => 'view', 'type' => 'json' )); Router::connect('/lab/{:controller}/{:action}/{:args}', array( 'plugin' => 'li3_lab', 'controller' => 'plugins' )); - - ?> diff --git a/controllers/PluginsController.php b/controllers/PluginsController.php index e495271..45c5c3a 100644 --- a/controllers/PluginsController.php +++ b/controllers/PluginsController.php @@ -39,13 +39,22 @@ class PluginsController extends \lithium\action\Controller { * @param string $id */ public function view($id = null) { - $plugin = Plugin::find($id); + if (strlen($id) > 30) { + $plugin = Plugin::find($id); + } else { + $plugin = Plugin::find('first', array( + 'conditions' => array( + 'design' => 'by_field', 'view' => 'name', + 'key' => json_encode($id) + ) + )); + } if (empty($plugin)) { $this->redirect(array('controller' => 'plugins', 'action' => 'error')); } if ($this->request->type == 'json') { - $this->render(array('json' => compact('plugin'))); + $this->render(array('json' => $plugin->data())); } return compact('plugin'); } diff --git a/models/LabView.php b/models/LabView.php index d2da745..30d0723 100644 --- a/models/LabView.php +++ b/models/LabView.php @@ -63,6 +63,17 @@ class LabView extends \lithium\data\Model { }' ) ) + ), + 'by_field' => array( + 'id' => '_design/by_field', + 'language' => 'javascript', + 'views' => array( + 'name' => array( + 'map' => 'function(doc) { + emit(doc.name, doc); + }' + ), + ) ) );