Display information in a select with view js and fat free

65 views
Skip to first unread message

remy

unread,
Apr 25, 2019, 4:46:32 AM4/25/19
to Fat-Free Framework

Here, I am confronting the following problem since yesterday I try to fill my select field with the fat-free framework.

I try to use axios as in most tutorial, I point to "response.data" but nothing fills in my field.


I have this code in my model :


public function ReadUserData($action) {
       
if (strcmp($action, "read") == 0) {
           
global $f3;
            $user
= $this->db->exec("SELECT * FROM users");
           
return json_encode($user);
       
}
   
}

I have this in my controller :


 $Users = new UserModel($this->db);
        $DataUser
= $Users->ListDatabaseUser();
   
if (isset($_GET['action'])) {
      $data
= $Users->ReadUserData($_GET['action']);
      $f3
->set("users", $data);
   
}

and in vue js i have :


Saisissez le c
<script type="text/javascript">
 
var Myapp = new Vue({
  el
: "#app",
  delimiters
: ['{%', '%}'],
  data
: {
    heading
: 'test',
    dataSelect
: null,
    makes_options
: []
 
},
  created
() {
    axios
.get('http://localhost/?action=read')
   
.then(function(response) {
         
Myapp.make_options = response.data;
          console
.log(Myapp.make_options);
     
});
 
}

});

Here, I am confronting the following problem since yesterday I try to fill my select field with the fat-free framework.

I try to use axios as in most tutorial, I point to "response.data" but nothing fills in my field.

I have this code in my model :

    public function ReadUserData($action) {
        if (strcmp($action, "read") == 0) {
            global $f3;
            $user = $this->db->exec("SELECT * FROM users");
            return json_encode($user);
        }
    }

I have this in my controller :

        $Users = new UserModel($this->db);
        $DataUser = $Users->ListDatabaseUser();
    if (isset($_GET['action'])) {
      $data = $Users->ReadUserData($_GET['action']);
      $f3->set("users", $data);
    }

and in vue js i have :

<script type="text/javascript">
  var Myapp = new Vue({
  el: "#app",
  delimiters: ['{%', '%}'],
  data: {
    heading: 'test',
    dataSelect: null,
    makes_options: []
  },
  created() {
    axios.get('http://localhost/?action=read')
    .then(function(response) {
          Myapp.makes_options = response.data;
          console.log(Myapp.makes_options);
      });
  }

});

I also try to remplace :

Myapp.makes_options = "{{ @users }}" but without sucess :/


For display that i have this in html :


Saisissez le code ici...
<label for="Select">Select</label>
    <select class="form-control" name="dataSelect" id="dataSelect" v-model="dataSelect">
      <option v-for="option in makes_options" :value="option.id">{% option.username %}</
option>
   
</select>



Currently my field is empty and I do not understand why my json is not interpreted correctly





Yaroslav Beregovoy

unread,
Apr 25, 2019, 7:14:39 AM4/25/19
to remy via Fat-Free Framework
first of all i don`t see the `return` statement of your sql query, try to do this:
public function getUsers() : array
{
    return $this-db->exec('SELECT * FROM users');
}

and do not forget about routes :
GET /getusers=    YourControllerHandler->someMethod

cheers

--
-- You've received this message because you are subscribed to the Google Groups group. To post to this group, send an email to f3-fra...@googlegroups.com. To unsubscribe from this group, send an email to f3-framework...@googlegroups.com. For more options, visit this group at https://groups.google.com/d/forum/f3-framework?hl=en
---
You received this message because you are subscribed to the Google Groups "Fat-Free Framework" group.
To unsubscribe from this group and stop receiving emails from it, send an email to f3-framework...@googlegroups.com.
To post to this group, send email to f3-fra...@googlegroups.com.
Visit this group at https://groups.google.com/group/f3-framework.
To view this discussion on the web visit https://groups.google.com/d/msgid/f3-framework/44c7462e-9ee6-45aa-aec7-782923f11e80%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Antonio Diaz

unread,
May 5, 2019, 8:57:29 AM5/5/19
to Fat-Free Framework
Hi,

try without the "return json_encode($user);",

use "return $user;"

Antonio
Reply all
Reply to author
Forward
0 new messages