Love Fuel?    Donate

FuelPHP Forums

Ask your question about FuelPHP in the appropriate forum, or help others by answering their questions.
Am having problems getting the metadata from ormauth
  • What is the way to get the metadata? 

    am tra traying to do this:

    $data['users'] = \Model\Auth_User::query()->related('metadata')->get();

    but the array dont return the metadata fields only the user data



  • If you run above query you will get an object of type \Model\Auth_user which has an array-property "metadata" under which you can find all the properties. Simply foreach-looping over it gives you each row of the "users_metadata" table. If you only want all the metadata, you should go either that way and copy the content of $user->metadata, or you go over \Model\Auth_Metadata and query against the user's ID.

    Hope that helps.
  • I printed the array with var_dump() and the related data is empty

  • I see in this dump a metadata object for every user, but I can't see it's contents. So so far, so good.
  • CONTROLLER------------

    public function action_index(){

    $data['users'] = \Model\Auth_User::query()->related('metadata')->get();
    $this->template->title = "Users";
    $this->template->content = View::forge('admin/users/index', $data);

    }

    VIEW-----------------

    <?php exit(var_dump($users)); ?>

    I DON'T KNOW WHAT IS WRONG!!!  :-(
  • I found in config.php

    'profiling'  => true,

    anyway, thanks to everybody
  • How did that solve your problem? That only shows you the SQL generated by the ORM.

    Lets break your query down:
    - you're doing a get(), so you get an array returned
    - you're asking for metadata, which is a one-to-many related object, so another array

    This means you need to loop twice to get all data:

    foreach ($users as $user)
    {
        foreach($user->metadata as $metadata)
        {
            echo sprintf("%s: %s<br />", $metadata->key, $metadata->value);
        }
    }

  • foreach ($users as $item): 
    echo $item->email; 
    echo $item['fullname']; 

    For some reason i the query don't was working  and now is working :-0
    very simple and clean

  • Yup, that works too (but only because metadata is implemented as an EAV container). For other relations you will need the double loop.

    (just want to be complete in my answer)

Howdy, Stranger!

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

In this Discussion