ci_bootstrap_3
ci_bootstrap_3 copied to clipboard
Hide restricted menu items
Edit in MY_Controller. Also edits the Error class from #61
The idea is simple, if the page is restricted, there's no point the user should be seeing the link. The first half of the ForEach looks for the main link group, while the second half kills the subitems. It's not pretty but it works for right now.
// restrict pages
$uri = empty($this->mModule) ? $this->uri->uri_string() : str_replace($this->mModule.'/', '', $this->uri->uri_string());
if ( !empty($this->mPageAuth[$uri]) && !$this->ion_auth->in_group($this->mPageAuth[$uri]) )
{
$redirect_url = empty($this->mModule) ? 'syserr' : $this->mModule.'/syserr';
redirect($redirect_url);
}
// restrict pages in menu
foreach($this->mMenu as $k=>$v) {
if (!empty($this->mPageAuth[$k]) && !$this->ion_auth->in_group($this->mPageAuth[$k])) {
unset($this->mMenu[$k]);
}
if (isset($this->mMenu[$k]['children'])) {
foreach ($this->mMenu[$k]['children'] as $ck => $cv) {
if (!empty($this->mPageAuth[$cv]) && !$this->ion_auth->in_group($this->mPageAuth[$cv])) {
unset($this->mMenu[$k]['children'][$ck]);
}
}
}
}