Hey folks,
I have several functions in my controllers that are breaking the DRY
convention - at the moment, in each one that needs to check the users
level does so at the top of the method. Here is an example:
function index($post_index_limit='1',$post_index_order='DESC',
$post_index_cachetime = '1 hour')
{
$level_check = $this->othAuth->group('level');
if (!empty($level_check))
{
$level = $level_check;
} else {
$level = 0;
}
// Overide paginate limit, may need to change
$this->cacheAction = $post_index_cachetime;
$this->passedArgs['limit'] = $post_index_limit;
$this->passedArgs['order'] = array('Post.post_date' =>
$post_index_order, 'Post.created' => $post_index_order);
$this->set('posts', $this->paginate(null,
array('Post.published'=>1,
'Post.frontpage' => 1 ,'Post.access_level' => '<= ' . $level )));
}
What I have tried to far is to move the level check into the model,
and return the value of level, then in my controller I tried this:
$this->set('posts', $this->paginate(null, array('Post.published'=>1,
'Post.frontpage' => 1 ,'Post.access_level' => '<= ' .
$this->Post->checklevel() )));
But then I get the error that the group method is not accessable - so
a controller seems to not be accessable from a model.
Can anyone see a way I can move this code into my app model (or app
controller - which I also couldn't get to work). I think once I get
this the first time, it should help me slim down a lot of my code.
Thanks,
Tane
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---