modifiedcontent Posted February 17, 2018 Posted February 17, 2018 I have one central website, with membership registration and content etc., and then several related websites with their own URL/domains, each on Processwire, all on the same server. I would like to access the database of the central website from the sister websites. How would I do that? You can't bootstrap one PW installation into another. You can include template parts from one in the other by just using the server path, but whatever you try to get/post just comes/goes to the database of the site you are on. Could you switch databases by including the config.php from another PW installation somewhere? What is the correct, secure way to do this?
horst Posted February 17, 2018 Posted February 17, 2018 Did you have read this? https://processwire.com/blog/posts/multi-instance-pw3/ 5 1
modifiedcontent Posted February 17, 2018 Author Posted February 17, 2018 Thanks horst, I vaguely remembered hearing something about this, but couldn't find it. This looks perfect for my use case. I'll try this and will report back... 1
horst Posted February 17, 2018 Posted February 17, 2018 1 minute ago, modifiedcontent said: I vaguely remembered hearing something about this, but couldn't find it Yep, that's how it is often. Also I tried to bookmark all interersting stuff (with several systems of subfolders), it ever ended up unusable, just because of the amount of bookmarks collected by the time. 1 1
modifiedcontent Posted February 18, 2018 Author Posted February 18, 2018 I kinda use this forum to keep track of how-to's and things I need. Your response will probably be useful to others looking for the same kind of thing. Tested it. Very cool. Dumping this into a template of another PW installation on the same server works: <?php $mainsite = new ProcessWire('/home/serverpath/public_html/mainsite/site/', 'https://mainsite.com/'); if($input->post->createuser) { $item = $mainsite->users->add('fred'); echo 'hello ' . $item->name; } $skyscrapers = $mainsite->pages->find('parent=skyscrapers, limit=3'); foreach($skyscrapers as $skyscraper) { echo '<h4>' . $skyscraper->title . '</h4>'; } ?> <form method=post> <input type=submit name=createuser value='add Fred to the main site'> </form> Fred gets added as a user to the main site. Pulling in content from the main site is straightforward. Is there a way to check if a user is loggedin on the main site?
Sergio Posted February 18, 2018 Posted February 18, 2018 (edited) 4 hours ago, modifiedcontent said: Is there a way to check if a user is loggedin on the main site? $bool = $user->isLoggedin(); https://processwire.com/api/ref/user/is-loggedin/ Edited February 18, 2018 by Sergio Added link to API page 2
kongondo Posted February 18, 2018 Posted February 18, 2018 4 hours ago, modifiedcontent said: $skyscrapers = $forum->pages->find('parent=skyscrapers, limit=3'); Forgot to show where $forum is defined in your example code? Would be good to show the complete, correct code to help others, thanks. 1 1
modifiedcontent Posted February 18, 2018 Author Posted February 18, 2018 Oops, kongondo. $forum should have been $mainsite. Now corrected in the example. @ Sergio, I know that, but is there a way to make that work from a "sister site" with this method? $mainsite->user->isLoggedin(); doesn't work. 1
kongondo Posted February 18, 2018 Posted February 18, 2018 2 hours ago, modifiedcontent said: $mainsite->user->isLoggedin(); doesn't work. Yeah, I can confirm this. From my testing ,$mainsite does not seem to have access to $session. Security? I don't know, just guessing. 1
modifiedcontent Posted February 18, 2018 Author Posted February 18, 2018 Saving a complete user object also doesn't seem to work. When I try something like this, only the username gets saved, none of the other fields - except maybe addRole: $u = new User(); $u->of(false); $u->firstname = $sanitizer->text($input->post->firstname); $u->lastname = $sanitizer->text($input->post->lastname); $u->name = $sanitizer->text($input->post->name); $u->email = $sanitizer->email($input->post->email); $u->registrationDate = time(); $u->addRole(''); $mainsite->users->save($u); Or am I doing something wrong? This works: $newuser = $mainsite->users->add(); $u = $mainsite->users->get( $newuser->id ); $u->of(false); $u->firstname = $sanitizer->text($input->post->firstname); $u->lastname = $sanitizer->text($input->post->lastname); $u->fullname = $u->firstname.' '.$u->lastname; $u->name = $sanitizer->text($input->post->username); $u->email = $sanitizer->email($input->post->email); $u->registrationDate = time(); $u->addRole(''); $mainsite->users->save( $u ); 1
kongondo Posted February 19, 2018 Posted February 19, 2018 1 hour ago, modifiedcontent said: Saving a complete user object also doesn't seem to work. When I try something like this, only the username gets saved, none of the other fields - except maybe addRole: Similar(-ish) issue?
dragan Posted February 19, 2018 Posted February 19, 2018 Did you try out $config->sessionAllow from the last chapter here https://processwire.com/blog/posts/multi-instance-pw3/#more-session-control? Although... I'm not sure if this is related to the main subject of the blog post (multi-instance) or not...
kongondo Posted February 19, 2018 Posted February 19, 2018 10 hours ago, modifiedcontent said: $newuser = $mainsite->users->add(); $u = $mainsite->users->get( $newuser->id ); $u->of(false); $u->firstname = $sanitizer->text($input->post->firstname); $u->lastname = $sanitizer->text($input->post->lastname); $u->fullname = $u->firstname.' '.$u->lastname; $u->name = $sanitizer->text($input->post->username); $u->email = $sanitizer->email($input->post->email); $u->registrationDate = time(); $u->addRole(''); $mainsite->users->save( $u ); Excellent! I don't think you need $u->of(false) for a new record/page, btw. Btw2, I testing saving a field in an existing $mainsite->somePage and it worked OK. However, I noticed two things: I expected PW to throw an error if I attempted to save the page without turning output formatting off, but it didn't Reloading the page where I was viewing content from $mainSite->somePages, the changes made to the above field were only visible after a 2nd reload Did you experience this @modifiedcontent?
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