saml Posted November 1, 2015 Share Posted November 1, 2015 (edited) Btw, just found the wireshell tool ... wow! ... but it doesn't seem to be able to import page content, only creating pages? Well, I made a little hack to it now, so it can take field contents as a JSON string on the commandline. Will try it out a bit and see if it fulfills my importing needs. EDIT: Updated link to new pull request. Edited December 8, 2015 by saml Link to comment Share on other sites More sharing options...
grigorisk Posted December 15, 2015 Share Posted December 15, 2015 hi!i'm trying to create a child for my page in form submit via ajax but i have this error "Fatal error: Class 'Page' not found in /home/chaniataxi/public_html/site/templates/insertReservations.php on line 4" the code in insertReservations.php is $p = new Page(); // create new page object // <--line 4 $p->template = 'insertReservations'; // set template $p->parent = wire('pages')->get('/my-reservations/'); // set the parent $p->name = $name."-".$sname.'reservation'; // give it a name used in the url for the page $p->title = 'Νέα κράτηση στο όνομα'.$name." ".$sname; // set page title (not neccessary but recommended) // added by Ryan: save page in preparation for adding files (#1) $p->save(); same with soma's codei create a template for insertReservations.php with name insertReservationsmy processwire version is 2.6.1did anyone know why i have that error? Link to comment Share on other sites More sharing options...
Lance O. Posted December 15, 2015 Share Posted December 15, 2015 I've always used a PHP file that resides outside of PW and included an include to the index.php page, but if you are working within PW, you probably don't need to include this at the top of your template: include("/home/path/to/public_html/index.php"); 1 Link to comment Share on other sites More sharing options...
grigorisk Posted December 15, 2015 Share Posted December 15, 2015 thanks man!!!you save my day in office!! 1 Link to comment Share on other sites More sharing options...
alan Posted March 10, 2016 Share Posted March 10, 2016 Just a comment about stating both a name and a title here. If you set both then it's up to you to ensure that the URL of the page is unique—heavy caveat, I think I am correct in stating this... Certainly I found an error on the 2nd page creation (with some super dumb test code that did not even try to create unique URLs for pages; so probably not unexpected!), but then I was looking at how to make pages unique etc when I found I was trying too hard... I noted the error I was getting and Wanze's comment that solved my problem here, short answer, don't set a name and PW does it all for you 1 Link to comment Share on other sites More sharing options...
Soma Posted March 11, 2016 Author Share Posted March 11, 2016 Or you can use adjustName=>true option in the save. 4 Link to comment Share on other sites More sharing options...
gebeer Posted March 11, 2016 Share Posted March 11, 2016 Or you can use adjustName=>true option in the save. One of those hidden beauties that would be great to have them in the Cheat Sheet... 2 Link to comment Share on other sites More sharing options...
bernhard Posted May 26, 2016 Share Posted May 26, 2016 hi soma, as this is a very popular post i think it should be mentioned, that there's a best practise for adding pages stated by ryan here: https://processwire.com/blog/posts/processwire-2.6.21-upgrades-comments-more-on-pw-3.x/#more-updates-on-processwire-3.0 $page = $this->wire(new Page()); maybe you can update your post? could save lots of troubles when using multiple instances of pw3 and i think all of us should take care of such things as soon as possible as they are working also in earlier versions 1 Link to comment Share on other sites More sharing options...
Soma Posted May 26, 2016 Author Share Posted May 26, 2016 hi soma, as this is a very popular post i think it should be mentioned, that there's a best practise for adding pages stated by ryan here: https://processwire.com/blog/posts/processwire-2.6.21-upgrades-comments-more-on-pw-3.x/#more-updates-on-processwire-3.0 $page = $this->wire(new Page()); maybe you can update your post? could save lots of troubles when using multiple instances of pw3 and i think all of us should take care of such things as soon as possible as they are working also in earlier versions Thanks bernhard for the hint. But this is only in modules and when multi-instance is used. The example here is in a bootstrap where there's no $this. What do you mean by "they are working also in earlier versions" ? As those multi-instance examples like $page = $this->wire(new Page()); isn't possible in 2.7 for example. Or am I wrong? 1 Link to comment Share on other sites More sharing options...
bernhard Posted May 26, 2016 Share Posted May 26, 2016 ah, you are right - that was my mistake! still new to all this OOP and namespacing but i'm making progress Link to comment Share on other sites More sharing options...
Artomultiplo Posted April 9, 2018 Share Posted April 9, 2018 I know that this post is a little old ut it should work even now, right? My question is: what's the content of that index.php that @Soma included in the first line? Link to comment Share on other sites More sharing options...
bernhard Posted April 9, 2018 Share Posted April 9, 2018 @Artomultiplo of course everything is still working. The index.php file is the main processwire file, see https://processwire.com/api/include/ If you only want to create new pages from inside processwire (eg in a template file) you don't need to include index.php, because processwire is already booted. 2 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted April 9, 2018 Share Posted April 9, 2018 @Artomultiplo check out these docs. 1 Link to comment Share on other sites More sharing options...
Artomultiplo Posted April 9, 2018 Share Posted April 9, 2018 Thank you all very much! I've instead used the "insert into template" method, but the include method is a lot better. I'm just starting up my processwire exploration with a project where I need to get some data from a JSON from a movie booking app and I'm actually doing giant steps considering that this is my first time with JSON and/or PHP. Is amazing, I'm doing stuff that I could only dream of when working with wordpress. I'm soooo exited... for real. This is the gist of what I'm using for creating the pages based on a json that I pull from an URL https://gist.github.com/protorob/e6050c78b4bee2dbce59c38234afa0de Any suggestion is well received. Thanks again fr your support! 2 Link to comment Share on other sites More sharing options...
bernhard Posted April 9, 2018 Share Posted April 9, 2018 4 minutes ago, Artomultiplo said: Is amazing, I'm doing stuff that I could only dream of when working with wordpress. I'm soooo exited... for real. Welcome to the world of ProcessWire Same feeling here for the last 4 Years Regarding your code: Maybe you need to check if the given pagename already exists. Not sure if that happens automatically or not, but you should definitely try and see if it throws an error. 1 Link to comment Share on other sites More sharing options...
Ivan Gretsky Posted April 9, 2018 Share Posted April 9, 2018 @Artomultiplo, you could set Movie_Type and Movie_Category as Page Fields to interlink you content. See here for some inspiration. 1 1 Link to comment Share on other sites More sharing options...
Artomultiplo Posted April 9, 2018 Share Posted April 9, 2018 Will look into that as soon as I figure out who to do it :-P 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