Jump to content

[SOLVED] update single field by visit


Martinus
 Share

Recommended Posts

Is there any information about updating a field value at viewing the page, with a name or number?

I looked in the docs and cheatsheet and read about

$page->set("field", $value);
$field->save();

but have no clue on how to implement this. I cannot find any examples either. 


Found this code just now:

echo "old" . $page->numbers;
$p = $page->numbers;
++$p;
echo "new " . $p;
$numbers = $p;
$page->save($numbers);

But is not updating the field ?

 

Link to comment
Share on other sites

hi,
just to explain what @iank said, first of all your $page->save($number) couldn't work because what is number, where to save it and so on ?
to do it the way you were going to, you would have to write

$number = $page->number != '' ? $page->number: 0;
echo $number;
$number++;
echo '<br />new' . $number;
$page->of(false);
$page->number = $number;
$page->save();

and, as you can see @iank solution is faster and, quite often, when coding the shorter, the better ?

have a nice day

  • Like 1
Link to comment
Share on other sites

  • Martinus changed the title to [SOLVED] update single field by visit
33 minutes ago, Martinus said:

But I still think it is difficult to find information like this in the API

Really? I think the api search function is good ? 

Just search for „save field value“ and the First result is setAndSave…
https://processwire.com/search/?q=save+field+value&t=API
https://processwire.com/api/ref/page/set-and-save/

Link to comment
Share on other sites

I was searching for 'update field' 'updating field values' etc.
In my mind, I had to 'update' the field, since it was already there.
But looking at $page->field and $page->save() - were it says: 

$pages->saveField($page, $field)

was the only thing coming close. Maybe it just does not work ?

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...