rareyush Posted January 12, 2018 Posted January 12, 2018 I am trying to add a file type field in a template but when I give access to the template I receive this error Error: Exception: New page '//' must be saved before files can be accessed from it (in /mysite/wire/core/PagefilesManager.php line 342) #0 /mysite/wire/core/PagefilesManager.php(328): ProcessWire\PagefilesManager->___path() #1 /mysite/wire/core/PagefilesManager.php(268): ProcessWire\PagefilesManager->path() #2 /mysite/wire/core/PagefilesManager.php(106): ProcessWire\PagefilesManager->createPath() #3 /mysite/wire/core/PagefilesManager.php(90): ProcessWire\PagefilesManager->init(Object(ProcessWire\Page)) #4 /mysite/wire/core/Page.php(3498): ProcessWire\PagefilesManager->__construct(Object(ProcessWire\Page)) #5 /mysite/wire/core/Pagefiles.php(132): ProcessWire\Page->filesManager() #6 /hom This error message was shown because: you are logged in as a Superuser. Error has been logged.
kixe Posted January 13, 2018 Posted January 13, 2018 This is an old issue. I use the following workaround. In case of an unsaved page instance (id = 0) a hook is called from the render() method of my custom module, which provides a form (withfile field) based on a PW template in the frontend: $this->addHookBefore('PagefilesManager::path', function ($e) { $e->replace = true; $e->return = null; }); https://github.com/ryancramerdesign/ProcessWire/issues/1259
rareyush Posted January 14, 2018 Author Posted January 14, 2018 On 1/13/2018 at 11:30 AM, kixe said: This is an old issue. I use the following workaround. In case of an unsaved page instance (id = 0) a hook is called from the render() method of my custom module, which provides a form (withfile field) based on a PW template in the frontend: $this->addHookBefore('PagefilesManager::path', function ($e) { $e->replace = true; $e->return = null; }); https://github.com/ryancramerdesign/ProcessWire/issues/1259 this one doesn't work
kixe Posted January 14, 2018 Posted January 14, 2018 Please post your code or explain exactly what you are doing. 1
rareyush Posted January 15, 2018 Author Posted January 15, 2018 12 hours ago, kixe said: Please post your code or explain exactly what you are doing. from admin panel I created new field whose type I choose 'file'. i have a template for contact form where i want to put this field and give access to upload files options to users but when i add this new field in that template my site stops working, i saw that error which i posted above everywhere.
kixe Posted January 15, 2018 Posted January 15, 2018 Put the code I have posted in your ready.php and replace $this with $wire. $wire->addHookBefore('PagefilesManager::path', function ($e) { $e->replace = true; $e->return = null; }); 2
rareyush Posted January 15, 2018 Author Posted January 15, 2018 12 hours ago, kixe said: Put the code I have posted in your ready.php and replace $this with $wire. $wire->addHookBefore('PagefilesManager::path', function ($e) { $e->replace = true; $e->return = null; }); Thanks kixe Love you a lot, you solved my big problem, I was trying to add that code in my main file & in init file. Thanks a lot
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