ziudeso Posted August 17, 2017 Share Posted August 17, 2017 Hi all, before submitting my question I wanna compliment with the Processwire dev team! You guys not only have managed to create a crazy-simple framework in its core concepts but are empowering people like me to understand clean and pure PHP scripting! Here's my question: I'm having troubles to implement a simple initDb.sh file that sets up the entire page hierarchy and structure. The code is: #!/usr/bin/php <?php include("./index.php"); // bootstrap ProcessWire ... function createMockUsers() { $item = new ProcessWire\User(); $item->setOutputFormatting(false); $item->name = $wire->sanitizer->pageName("newname"); $item->pass = "yo12345"; $item->email = $wire->sanitizer->email("example@processwire.com"); $item->addRole('guest'); $item->save(); } ... createMockUsers(); The error is: Error: Call to a member function pageName() on null Additionally, is there a better way to initialize a Processwire structure rather than using an external script? Aand, is there a nicer syntax for instantiating new classes (not like " $item = new ProcessWire\User();") Thank you guys for your support and the wonderful piece of software you made! Link to comment Share on other sites More sharing options...
abdus Posted August 17, 2017 Share Posted August 17, 2017 If you define the namespace on top of your script, you wont have to prefix functions with \Processwire\ #!/usr/bin/php <?php namespace ProcessWire; // remember to include namespace include("./index.php"); // bootstrap ProcessWire // ... function createMockUsers() { $u = new User(); $u->of(false); // short for outputFormatting // inside closure you cannot access global $wire variable // unless you set function myFunction() use ($wire) {} // but you can call wire() function instead $u->name = wire()->sanitizer->pageName("newname"); $u->pass = "yo12345"; $u->email = wire()->sanitizer->email("example@processwire.com"); $u->addRole('guest'); $u->save(); } // ... createMockUsers(); 3 Link to comment Share on other sites More sharing options...
ziudeso Posted August 22, 2017 Author Share Posted August 22, 2017 Man, you are the best!! Can't find the "Solved" button if any tho =) Link to comment Share on other sites More sharing options...
abdus Posted August 22, 2017 Share Posted August 22, 2017 Happy to be of help. IIRC, there used to be a "mark as solved" button. I remember seeing a green answer on the top. I guess it's been removed. In the meantime there's the like button. Link to comment Share on other sites More sharing options...
szabesz Posted August 22, 2017 Share Posted August 22, 2017 1 hour ago, abdus said: I guess it's been removed More than a year ago, with the last major Forum update because the current version does not support it anymore 2 Link to comment Share on other sites More sharing options...
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