Hello, i'm making a blog (basic stuff) and i'm trying to set the permission levels. Everything inside the model and the controller is working fine except the visual stuff. The problem started when i was trying to find the most efficient way to remove stuff like the edit or delete button then the user level i lowest than the accepted.
For example:
if a normal users tries to edit a post from the url he will be redirected back. The edit button is disabled. Same for other dangerous actions.
Code:
Code:
function post($postID)
{
//which post are your trying to edit son?
if(!$this->post->get_post($postID))
{
redirect(base_url().'posts');
}
else
{
//call the function
$this->correct_permissions('user');
/*
if(!$this->correct_permissions('author'))
{
$data['has_edit_perms'] = false;
}
else {
$data['has_edit_perms'] = true;
}
*/
//array
$data['post'] = $this->post->get_post($postID);
//header stuff
$this->load->view('__head__');
//pack the view and pass the data
$this->load->view('post', $data);
}
}
// no comment
function correct_permissions($required)
{
$user_type = $this->session->userdata('user_type');
if($required == 'user')
{
$data['perm_level'] = 1;
if($user_type)
{
return true;
}
}
elseif($required == 'subscriber')
{
$data['perm_level'] = 2;
if($user_type == 'admin' || $user_type == 'author' || $user_type == 'subscriber')
{
return true;
}
}
elseif($required == 'author')
{
$data['perm_level'] = 3;
if($user_type == 'admin' || $user_type == 'author')
{
return true;
}
}
elseif($required == 'admin')
{
$data['perm_level'] = 4;
if($user_type == 'admin')
{
return true;
}
}
}
If i call the correct_permissions() function it will work and it will tell me if the user has the required rank BUT i will not be able to access the value of $data['perm_level'] inside the view.
Used in the code:
Code:
<?php if($perm_level > 3): ?>
<a href="<?= base_url() ?>posts/new_post"> Create new post </a>
<?php endif; ?>
(if i use the commented code instead it will work but i want to make more dynamic thats why im using the other way)
Anyone knows why the 'perm_level' is not working?