diff --git a/app/plugins/cms/controllers/categories_controller.php b/app/plugins/cms/controllers/categories_controller.php index 59fce5ec0..14cb54851 100644 --- a/app/plugins/cms/controllers/categories_controller.php +++ b/app/plugins/cms/controllers/categories_controller.php @@ -6,7 +6,22 @@ class CategoriesController extends CmsAppController function index() { $this->Category->recursive = 0; - $this->set( 'categories', $this->paginate() ); + + $categories = $this->paginate(); + + // redirect if there is only one category. + if ( count( $categories ) == 1 && Configure::read( 'Cms.auto_redirect' ) ) + { + $this->redirect( + array( + 'controller' => 'categories', + 'action' => 'view', + $categories[0]['Category']['id'] + ) + ); + } + + $this->set( 'categories', $categories ); } function view( $id = null ) @@ -16,7 +31,22 @@ function view( $id = null ) $this->Session->setFlash( __( 'Invalid category', true ) ); $this->redirect( array( 'action' => 'index' ) ); } - $this->set( 'category', $this->Category->read( null, $id ) ); + + $category = $this->Category->read( null, $id ); + + // redirect if there is only one content item. + if ( count( $category['Content'] ) == 1 && Configure::read( 'Cms.auto_redirect' ) ) + { + $this->redirect( + array( + 'controller' => 'contents', + 'action' => 'view', + $category['Content'][0]['id'] + ) + ); + } + + $this->set( 'category', $category ); } function admin_index() diff --git a/app/plugins/cms/controllers/sections_controller.php b/app/plugins/cms/controllers/sections_controller.php index 168d89cc5..bd7d632af 100644 --- a/app/plugins/cms/controllers/sections_controller.php +++ b/app/plugins/cms/controllers/sections_controller.php @@ -5,8 +5,21 @@ class SectionsController extends CmsAppController function index() { - $this->Section->recursive = 0; - $this->set( 'sections', $this->paginate() ); + $this->Section->recursive = 1; + $sections = $this->paginate(); + + if ( count( $sections ) == 1 && Configure::read( 'Cms.auto_redirect' ) ) + { + $this->redirect( + array( + 'controller' => 'sections', + 'action' => 'view', + $sections[0]['Section']['id'] + ) + ); + } + + $this->set( 'sections', $sections ); } function view( $id = null ) @@ -16,7 +29,21 @@ function view( $id = null ) $this->Session->setFlash( __( 'Invalid section', true ) ); $this->redirect( array( 'action' => 'index' ) ); } - $this->set( 'section', $this->Section->read( null, $id ) ); + + $section = $this->Section->read( null, $id ); + + // redirect if there is only one category. + if ( count( $section['Category'] ) == 1 && Configure::read( 'Cms.auto_redirect' ) ) + { + $this->redirect( + array( + 'controller' => 'categories', + 'action' => 'index' + ) + ); + } + + $this->set( 'section', $section ); } function admin_dashboard()