Jump to content

Recommended Posts

Posted

Hello,

I'm trying to get a file url, using ajax with the page ID :

$file = wire('pages')->get($id)->file->url;

But it outputs the file url without the filename :

/site/assets/files/xxxx/ instead of /site/assets/files/1017/filename.ext

No problem from a template file...

Any solution ? Thanks !

Posted

Bootstrap use, presumably? In that case output formatting is off and field value is returned in array format. You'll need to call wire('pages')->get($id)->file->first()->url etc.

  • Like 2
Posted

@teppo : i forgot to try that... and it works ;) Thanks !

@marcus : yes only one value, so the first() parameter should be useless, no ? In a template file, it works without the first() param.

Posted

@mvdesign: sorry, corrected my earlier post -- meant to say bootstrap use, not API use. The principle was correct, though; if I'm guessing right, you're bootstrapping ProcessWire, and thus output formatting is always disabled and file fields will always return arrays, regardless of output settings (including the "output single item if limit is one" setting).

  • Like 1
Posted

I already know the problem/answer just by reading post titles like this one in this forum. This problem has come up and answered 1001 times at least. 

I even got in a heated discussion with a co-worker about this, where he just don't get outputformatting, even after explaining him multiple times again and again. He even insisted on that in his particular case it doesn't work even though it should have... 

Posted

When you say Ajax in your first post, do you mean API? I don't see any Ajax.

Posted

Thanks guys.

@teppo : thanks for the explaination, now i understand.

@Pete : what i mean is use variable in external php file, which require to use the $wire global variable (width ajax or not).

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
  • Recently Browsing   0 members

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