Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
I can't get the content of users table
  • Hi, I'm trying to make an admin panel for user management so I can create, update and delete users in my application. I managed to create the user using Auth::create_user(). But when it redirected to index page (of user management page). FuelPHP shows an error page : Fuel\Core\FuelException [ Error ]: Database results are read-only Can anybody explain why this happen?? Is there any mistakes in my code?? Here is my controller of index page and create user : public function action_index() {
    $view = View::forge('admin/user/index'); $this->template->title = 'Operator';
    $this->template->content = $view; $result = DB::select()->from('users')->where('group', '!=', 100)->execute();
    $view->set('opr', $result);
    } public function action_create() {
    if (Input::post()) {
    $username = Input::post('username');
    $password = Input::post('password');
    $email = Input::post('email'); if (Auth::create_user($username, $password, $email, 50)) {
    Session::set_flash('success', e('Berhasil menambahkan operator'));
    Response::redirect('user');
    } else {
    Session::set_flash('error', e('Gagal menambahkan operator'));
    }
    } $this->template->title = 'Operator';
    $this->template->content = View::forge('admin/user/create');
    } Any help appreciated. Thank you +
  • This is not an Auth question. The DB class by default returns database objects (like MySQLi_Result), which are per definition read-only. If you pass such an object to a view, FuelPHP will try to encode it like we encode all data that goes to the view. Which is not possible. You can convert the result of the DB query to an array using as_array(), or to objects of type stdClass using as_object(), or disable encoding by using set_safe() instead of set() to pass the data to the view (which is not recommended). ORM Models can also be passed to a view without problems.
  • Oh, sorry Harro, I just put it here because I use the Auth :) Thank you for the explanation, I understand now. And I managed to create, change password and delete user without having to show the data from users table. I just using the simple form to create, change password and deleting user. If it success, it will show a flash message. When I want to see if it works, I just take a look at phpMyadmin +

Howdy, Stranger!

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

In this Discussion