mvdesign Posted August 23, 2014 Posted August 23, 2014 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 !
teppo Posted August 23, 2014 Posted August 23, 2014 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. 2
marcus Posted August 23, 2014 Posted August 23, 2014 Have you set the field "file" to contain only one value?
mvdesign Posted August 23, 2014 Author Posted August 23, 2014 @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.
teppo Posted August 23, 2014 Posted August 23, 2014 @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). 1
Soma Posted August 23, 2014 Posted August 23, 2014 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...
Pete Posted August 24, 2014 Posted August 24, 2014 When you say Ajax in your first post, do you mean API? I don't see any Ajax.
mvdesign Posted August 25, 2014 Author Posted August 25, 2014 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).
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now