Jump to content

InputfieldPage and multi-instance support


snck
 Share

Recommended Posts

Hello,

in a project I use the multi-instance feature of ProcessWire to get content from another ProcessWire instance which is kind of a "database". I do not modify the external content. For a slider I want to store references to the "database" in an InputfieldPage. To get the available pages I use the following code in my ready.php:

$wire->addHookAfter('InputfieldPage::getSelectablePages', function($event) {
  if($event->object->hasField == 'kub_highlight_artworks') {

    // Server path to the PW installation
    $path = '/var/www/vhosts/.../';

    // The root URL for the PW installation
    $url = 'https://.../';

    // Create a new ProcessWire instance
    $db = new ProcessWire($path, $url);

    $event->return = $db->pages->find("template=artwork, sort=title");

  }
});

Outputting and selecting the external pages works perfectly fine, but unfortunately the selected pages do not get saved when I save the page.

Can someone point me into the right direction how to make this work? Are there any internal checks whether the page exists in the current instance that prevent saving the values?

Best,
Flo

Link to comment
Share on other sites

8 hours ago, snck said:

but unfortunately the selected pages do not get saved when I save the page.

Could you please show us your code for this bit?

Secondly, it is not clear whether you want to store pages from one instance in another instance. If that's the case, maybe this applies to you?

Quote

Be careful not to load objects from one instance and save them to another. Loaded objects are going to be connected with the instance they were loaded from. They might have a database ID unique to that installation, and so on. If you need to copy/move object data from one instance to save to another, convert to basic types and re-create the objects. For instance, if copying an image from one instance to another, do a $page->images->add($filename); rather than trying to add the Pagefile object from another installation.

https://processwire.com/blog/posts/multi-instance-pw3/#pitfalls-and-considerations

  • Like 2
Link to comment
Share on other sites

On 8/17/2020 at 9:15 PM, kongondo said:

Could you please show us your code for this bit?

Secondly, it is not clear whether you want to store pages from one instance in another instance. If that's the case, maybe this applies to you?

https://processwire.com/blog/posts/multi-instance-pw3/#pitfalls-and-considerations

There is no code for it. The pages are edited in the backend by editors using the normal page edit dialogue.

I do not try to store pages from one instance in the other, at least this is what I was thinking. From my understanding InputfieldPage is just storing references to pages which is what I want to achieve: Store references to pages of instance1 in a page on instance2.

Maybe this clears it up?

 

Link to comment
Share on other sites

4 hours ago, snck said:

Maybe this clears it up?

Sort of 😄  

4 hours ago, snck said:

Store references to pages of instance1 in a page on instance2.

This is still confusing. When you say store, do you mean store in memory? I am assuming that is what you mean since you said you are not doing any saving in your code. On the other hand, if you mean saving (i.e., database-storage-sort-of-saving) references to pages of instance1 in a page on instance2, then I am not sure how you can achieve that without having the pages in instance1 also present in instance2. You are using a Page Field and they cannot store external pages. Those pages must exist on the site the Page Field is present in.

4 hours ago, snck said:

From my understanding InputfieldPage is just storing references to pages which is what I want to achieve:

Again, maybe I am misunderstanding something, but InputfieldPage (all inputfields, in fact) do not store anything, if by store you mean save. Storage is achieved via Fieldtypes. 

Am I on the right track? :-) 

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
  • Similar Content

    • By xfroggy
      Hi!
      So I am trying to pull some information from another ProcessWire installation within the admin area (_main.php / page tree from the AdminThemeUikit module).
      $pwpath = "/path/"; $pwurl = "https://url.example"; $pw = new ProcessWire($pwpath , $pwurl); which then gives me this error
       
      I then read that if it is not already in a ProcessWire environment that I would have to include the core, 
      require('/path/to/wire/core/ProcessWire.php'); Which I tried, and makes sense that it already says it is included.
       
      So what now?
       
      Here is my _main.php from the AdminThemeUikit module (work in progress), just for reference
       
    • By swampmusic
      Having a problem with a basic multi-site instance.
      The multi-sites are dynamically created and run as sub-domains and all is ok with them. They are created during a sign up process by end users.
      During the sign up process - once the new site & db has been created, I had planned to load the new site instance and add a new user to it, using code similar to this..
      $newSiteInstance = new ProcessWire($path, $newSiteUrl);   $u = $newSiteInstance->users->add($sitename); $u->pass = $pass; $u->email = $email; $u->addRole('content-viewer'); $x = $newSiteInstance->users->save($u);  This won't work in the registration script. It throws an error ... "SQLSTATE[42S02]: Base table or view not found".
      However, if I halt the script, load the new site incognito/other browser, then continue the script, all works perfectly.
      So $newSiteInstance = new ProcessWire($path, $newSiteUrl); doesn't seem to work for me unless a site has already been loaded in a browser or instantiated somehow.
      I am missing something here ? Does a site need to be bootstrapped before new instance will work on it ? 
      Sorry, pretty new to this php/PW arena.  Having fun though
      Any ideas folks ?
       
    • By Marc
      I'm working on a process module that connects to another ProcessWire 3.0.54 installation on the same (local) server (both sites running 3.0.54). I'm trying to use multi-instance for this, so:
      namespace ProcessWire; $path = "C:/Users/Me/Documents/development/www/pw3/"; $url = "http://www.test.me"; $site = new ProcessWire($path, $url); Those simple three lines generate the following error:
      I'm probably missing something obvious here as I don't have much experience with namespaces yet. Any suggestions?
    • By Marc
      I have setup two websites, A and B. A can read pages from B using the multi-instance API. But how do I get A to save a new page to B? I have this simple test setup:
      $path = "C:/Users/Marc/Documents/development/www/siteB/"; $url = "/siteB/"; $siteB = new ProcessWire($path, $url); $np = new Page(); $np->template = "my-template"; $np->parent = $siteB->pages->get('/forms/'); $np->title = 'test multi-instance form'; $np->save(); The page is saved to site A instead of B, with no parent. Is this a case of saving it to the wrong instance? If so, how do I save it to the correct instance (site B)?
    • By Ferdi Derksen
      Hi guys,
      I was wondering if there is an option to load another site in the FieldtypePage by using the custom PHP code to find selectable pages.
      // placed as custom PHP code to find selectable pages return $content->pages->get("/")->children(); When it needs hooking into methods as "InputfieldPage::___getSelectablePages" or "InputfieldPage::___findPagesCode", I'd like to know how.
      By just placing the following code somewhere in the methods it won't work, but maybe someone else knows how?
      $content = new ProcessWire('/mypath/to/content/site/', '/content/'); // placed in subdirectory  
      Maybe it isn't even possible, but then also, I'd like to know .
×
×
  • Create New...