I've been using Fat Free Framework 3.6 for a while and I'm having some trouble making sure of a few things related to the variables used; also please note that I'm not that knowledgeable as a PHP programmer. Here are some examples (I'm using a few "shortcut" methods for the SQL mapper, but I guess it's still readable):
function testroute() {
// Q1 - Using f3-access to authorize a logged in user to advance on a route
$this->access->authorize($this->f3->get('SESSION.user.group_id'));
// Q2 - Change the f3 UPLOADS variable
$this->f3->update('UPLOADS', '/different/location');
// Q3 - Instantiante Users and User Groups from DB
$users = new User($this->db);
$userGroups = new UserGroups($this->db);
// Load all records to array
$arrayOfUsers = $users->all();
$arrayOfUserGroups = $userGroups->all();
// Make the arrays available to the template
$this->f3->set('arrayOfUsers', $arrayOfUsers );
$this->f3->set('arrayOfUserGroups', $arrayOfUserGroups );
// Render the View
$this->f3->set('view','content.test.htm');
$template=\Template::instance();
echo $template->render('layout.sidebar.htm');
}
Considering the example code above:
- Can the
SESSION.user.group_id
variable be tampered with/exploited by a logged in user, changing the value stored for its usergroup? If so, what is the/a more secure way of doing things like this, like having aisAdmin
flag set at login? - Does changing the
UPLOADS
variable makes it different for the entire hive (i.e. all users), or is the change only for the current user? Within the template, is there a way of using the
group_id
value of a givenuser
to get a different key of the relateduserGroup
, like it's slug? In the example below, I'm trying to avoid looping through@arrayOfGroups
and for that I tried using array_search, but it returns empty (actually it returns theslug
for id=0), i.e.:<include href="{{ 'navbar.htm' }} />
<repeat group="{{ @arrayOfUsers }}" value="{{ @item }}" >
<tr class=""> <td>{{ @item.username }}</td> <td>{{ @item.usergroup_id }}</td> <td>{{ @arrayOfUserGroups[array_search(@item.usergroup_id].slug }}</td> </tr>
</repeat>
In the last example, I have an
<include>
reference for a nav bar, which in turn will have<li></li>
elements for the nav items. What is the appropriate way of, using thistestroute()
controller, apply<li class="active"></li>
to a specific item?
Cheers