Skip to content

Commit

Permalink
adding auto redirect options to db and to cms where sections only hav…
Browse files Browse the repository at this point in the history
…e on category it will redirect to the category instead of showing a list of one category. this is configurable in Core.Config
  • Loading branch information
dogmatic69 committed Dec 28, 2009
1 parent f06349b commit 4a99820
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 5 deletions.
34 changes: 32 additions & 2 deletions app/plugins/cms/controllers/categories_controller.php
Expand Up @@ -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 )
Expand All @@ -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()
Expand Down
33 changes: 30 additions & 3 deletions app/plugins/cms/controllers/sections_controller.php
Expand Up @@ -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 )
Expand All @@ -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()
Expand Down

0 comments on commit 4a99820

Please sign in to comment.