Jump to content

Display $user->image error on Frontpage


kreativmonkey
 Share

Recommended Posts

Hi,

i will display the user profile image while the user is logged in. The image field is a single item and limited by 1.

My code to Display:

if(count($user->avatar)){
   echo "<a class='dropdown-toggle' href='#' data-toggle='dropdown' id='navUserImg'><img class='img-circle' src='".wire('user')->avatar->size(30,30)->url."'></img></a>";
 } else {
   echo "<a class='dropdown-toggle' href='#' data-toggle='dropdown' id='navUserFa'><i class='navUserFa fa fa-user fa-lg'></i></a>";
 }

Now when i'm on a page that i have created i will see my image. But when i load a page from another author so i get the following issue:

Expection: Method Pageimages::size does not exist or is not callable in this context

when i now change my code to this

if(count($user->avatar)){
    echo "<a class='dropdown-toggle' href='#' data-toggle='dropdown' id='navUserImg'><img class='img-circle' src='".wire('user')->avatar->first()->size(30,30)->url."'></img></a>";
  } else {
    echo "<a class='dropdown-toggle' href='#' data-toggle='dropdown' id='navUserFa'><i class='navUserFa fa fa-user fa-lg'></i></a>";
 }

It will work on the pages of other authors, but when i go back to pages that i have created so i get another issue:

Exception: Method Pageimage::first does not exist or is not callable in this context

For the moment i have set the output formatting as array so i can call ->first() and it works on all pages but that is not the right solution. Can anyone help me? what do i make wrong.

Link to comment
Share on other sites

Are you changing the output-formatting of the user page somewhere (e.g. to save things to it). Imagefields do only pretend to be single value if output-formatting is enabled for the page. Internally the file and image fields are always multi-value, independent of your settings in the backend.

Link to comment
Share on other sites

not that i know of! the only point i change the output formatting is in the import script for my posts but that is not load on this templates! i don't manipulate anything on the $user pages.

The image output works great on all pages (with any template) that i have created but it didn't work on the other pages on the same templates...

EDIT:

The full error while using $user->avatar->size(30,30)->url:

Fatal error: Exception: Method Pageimages::size does not exist or is not callable in this context (in /.../mtar/processwire/wire/core/Wire.php line 350) #0 
/.../mtar/processwire/wire/core/WireArray.php(1637): Wire->___callUnknown('size', Array) #1 
[internal function]: WireArray->___callUnknown('size', Array) #2 
/.../mtar/processwire/wire/core/Wire.php(387): call_user_func_array(Array, Array) #3 
/.../mtar/processwire/wire/core/Wire.php(325): Wire->runHooks('callUnknown', Array) #4 
/.../mtar/processwire/wire/core/Wire.php(329): Wire->__call('callUnknown', Array) #5 
/.../mtar/processwire/wire/core/Wire.php(329): Pageimages->callUnknown('size', Array) #6 
/.../mtar/processwire/site/templates/include/navbar.inc(66): Wire->__call('size', Array) #7 
/...mtar/processwire/site/templates/include/navbar.inc(66): Pageimages->size(30, 30) #8 
/.../mtar/processwire/site/templates/include/main.inc in /.../mtar/processwire/index.php on line 253

EDIT:

I use the Debug Code from adrian with the $user->avatar->url and this is the result:

              Time                User          Page               Value
vor 3 Minuten 2015-08-13 23:52:35 kreativmonkey /blog/altonarite/ /site/assets/files/41/picture-1-1384808667.jpg 
vor 4 Minuten 2015-08-13 23:51:53 kreativmonkey /blog/gossipibom/ /site/assets/files/41/

first is a page that i have created and the second is created by another user.

EDIT:

$user->of() is true on pages that i have created and false on pages from other users but i do nothing in the templates that can explain this behavior.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...