Jump to content

[solved] issue importing data with API


neosin
 Share

Recommended Posts

Hi all

I am bootstraping PW to import large batches of data however I am having a hard time importing the alternate language using the suggested method

I am using the language alternate field method as outlined here https://processwire.com/api/multi-language-support/multi-language-fields/#language-alternate-field-values

here is the code  I am using and the issue is that the French fields do not populate at all. The English data is fine but for some reason the French does not get filled in.

The name of the alt lang is "fr" and the title is "Français", so I assumed I could do $page->body_fr but this seems not to be the case?

while($row = $result->fetch_assoc()) {	  
	  $p = new Page();
	  $p->template = "video-item";
	  $p->parent_id = 1057;
	  $p->of(false); // outputFormatting must be OFF
	  $p->title = $row['title_en'];
	  $p->title_fr = $row['title_fr'];
	  $p->summary = $row['description_en'];
	  $p->summary_fr = $row['description_fr'];
	  $p->save();
}

The external database (non-PW) fields for French all exist and all have data.

It seems if I have outputFormatting on or off makes no difference, initially I did not have it but after reading the link above I added it but it has no effect so far.

What am I doing wrong?

Link to comment
Share on other sites

@maxf5 it gives error "Call to a member function setLanguageValue() on string"  but we are using $p->of(false); so it should be an array... I am confused

This is the update code which is giving this error now

while($row = $result->fetch_assoc()) {
	$fr = $languages->get("fr");  
	$p->of(false);

	$p->title = $row['title_en'];
	$p->title->setLanguageValue($fr, $row['title_fr']);
	$p->summary = $row['description_en'];
	$p->summary->setLanguageValue($fr, $row['description_fr']);
	$p->save();
}

 

Link to comment
Share on other sites

2 minutes ago, bernhard said:

 


$p->setLanguageValue($language, $field, $value);

You cannot call it from the $p->summary property ;)


Doesn't it work when he prefix his file with:

<?php namespace ProcessWire;
  • Like 1
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.
×
×
  • Create New...