Vokuro - How does user.successLogins work?

Hi All,

I am trying to figure out how the Vokuro example gets data from the successlogins table using user.successLogins in Volt. I have crated a new controller and I am now trying to do the same thing (with another table), but I cannot get it to work. I have created all the required replationships between the two tables, but I could not get it to work unless I select the data in the controller using magic getters and pass that as a variable to the view. However, in the Vokuro example, the controller (UsersController) does not do this. Can someone give me a hand here by explaining how can I acheive the same result?


Make sure you added the relation in the model. For the user successLogins example see app/models/Users.php:

public function initialize() {
  $this->hasMany('id', __NAMESPACE__ . '\SuccessLogins', 'usersId', array(
    'alias' => 'successLogins',
    'foreignKey' => array(
      'message' => 'User cannot be deleted because he/she has activity in the system'

The code is there, beacuse this works when used in the controller:


But this does not work in the view (using Volt):

{{ user.successLogins }}

You should give us more information about the error you get.

user.successLogins is a database query until you execute it, so it probably can't be converted to string and displayed. Your view file should look like this:

{% for login in user.successLogins %}
    <td>{{ login.id }}</td>
    <td>{{ login.ipAddress }}</td>
    <td>{{ login.userAgent }}</td>
{% endfor %}

This is the exact code I am using. It should display failed logins for the user

{% for fails in user.failedLogins %}
  <td>{{ fail.id }}</td>
  <td>{{ fail.ipAddress }}</td>
  <td>{{ fail.userAgent }}</td>
  <td>{{ date("Y-m-d H:i:s", fail.attempted) }}</td>
{% else %}
  <tr><td colspan="3" align="center">User has no failed login attempts</td></tr>
{% endfor %}

But I always get "User has no failed login attempts". However, when I pass the data from the controller like so

$this->view->failed = $user->failedLogins;

I can now use the code above simply by swapping




You have a typo. In the for statment it's fails and then fail.

Also you might want to use colspan="4"

Yeah, just a typo. It's fail in the view file