Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Assigning permissions to group
  • Hey, I'm trying to assign permissions to groups, and I'm constantly getting an exception, although the data is saved to the DB, 
    here is my code, am I doing something wrong?
    try {
    $group->name=input::post('name');
    foreach (Input::post('permission') as $selected_permission)
    {
    if(isset($group->permissions[$selected_permission]))
    {
    unset($group->permissions[$selected_permission]);
    }

    $group->permissions[$selected_permission] = \Auth\Model\Auth_Permission::find($selected_permission);
    }

    if($group->save())
    {
    Session::set_flash('success', e('Group Updated.'));
    Response::redirect(input::referrer());
    }
    else
    {
    Session::set_flash('error', e('Could not save Group Changes.'));
    }
    } catch (exception $e) {
    Session::set_flash('error', e('Could not save Group Changes.'.$e));
    }
  • Difficult to say without knowing the error. At first glace this looks ok to me.
  • 'PDOException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), `user_id` = 1, `updated_at` = 1434701328 WHERE `id` = '21'' at line 1' in C:\wamp\www\sermus\fuel\core\classes\database\pdo\connection.php:237 Stack trace: #0 C:\wamp\www\sermus\fuel\core\classes\database\pdo\connection.php(237): PDO->query('UPDATE `users_p...') #1 C:\wamp\www\sermus\fuel\core\classes\database\query.php(287): Fuel\Core\Database_PDO_Connection->query(3, 'UPDATE `users_p...', false) #2 C:\wamp\www\sermus\fuel\packages\orm\classes\query.php(1450): Fuel\Core\Database_Query->execute(NULL) #3 C:\wamp\www\sermus\fuel\packages\orm\classes\model.php(1420): Orm\Query->update() #4 C:\wamp\www\sermus\fuel\packages\orm\classes\model.php(1301): Orm\Model->update() #5 C:\wamp\www\sermus\fuel\packages\orm\classes\manymany.php(333): Orm\Model->save() #6 C:\wamp\www\sermus\fuel\packages\orm\classes\model.php(1311): Orm\ManyMany->save(Object(Auth\Model\Auth_Group), Array, Array, true, NULL) #7 C:\wamp\www\sermus\fuel\app\classes\controller\admin\groups.php(75): Orm\Model->save() #8 [internal function]: Controller_Admin_Groups->action_edit('10') #9 C:\wamp\www\sermus\fuel\core\classes\request.php(444): ReflectionMethod->invokeArgs(Object(Controller_Admin_Groups), Array) #10 C:\wamp\www\sermus\index.php(53): Fuel\Core\Request->execute() #11 {main} Next exception 'Fuel\Core\Database_Exception' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '), `user_id` = 1, `updated_at` = 1434701328 WHERE `id` = '21'' at line 1 with query: "UPDATE `users_permissions` SET `actions` = (), `user_id` = 1, `updated_at` = 1434701328 WHERE `id` = '21'"' in C:\wamp\www\sermus\fuel\core\classes\database\pdo\connection.php:270 Stack trace: #0 C:\wamp\www\sermus\fuel\core\classes\database\query.php(287): Fuel\Core\Database_PDO_Connection->query(3, 'UPDATE `users_p...', false) #1 C:\wamp\www\sermus\fuel\packages\orm\classes\query.php(1450): Fuel\Core\Database_Query->execute(NULL) #2 C:\wamp\www\sermus\fuel\packages\orm\classes\model.php(1420): Orm\Query->update() #3 C:\wamp\www\sermus\fuel\packages\orm\classes\model.php(1301): Orm\Model->update() #4 C:\wamp\www\sermus\fuel\packages\orm\classes\manymany.php(333): Orm\Model->save() #5 C:\wamp\www\sermus\fuel\packages\orm\classes\model.php(1311): Orm\ManyMany->save(Object(Auth\Model\Auth_Group), Array, Array, true, NULL) #6 C:\wamp\www\sermus\fuel\app\classes\controller\admin\groups.php(75): Orm\Model->save() #7 [internal function]: Controller_Admin_Groups->action_edit('10') #8 C:\wamp\www\sermus\fuel\core\classes\request.php(444): ReflectionMethod->invokeArgs(Object(Controller_Admin_Groups), Array) #9 C:\wamp\www\sermus\index.php(53): Fuel\Core\Request->execute() #10 {main}

    Seems like for some reason it's trying to do some query to update "users_permissions" ? 
    I dunno, I couldn't understand what's going on without deep understanding of Auth Package, I guess I will have to dig into it to know what's going on, if you can give a hint or something that would be appreciated, am not asking for a complete solution or a ready piece of cake. 
  • HarroHarro
    Accepted Answer
    "users_permissions" is the table that holds the permissions, for some reason it sees Permission with ID# 21 as changed and wants to update it.

    And that fails because 'actions' is passed an empty array instead of a string, which is where the "()" in the query comes from, DB will convert an array into a set of values, so this indicates an empty array.

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

In this Discussion