Updating a long form

34 views
Skip to first unread message

Bede Northcote

unread,
Apr 15, 2022, 5:11:18 AM4/15/22
to redbeanphp
I am updating all of my code from v1 of RedBeanPHP to the current version.  With Gabor's advice, I have made quite a lot of progress, but am stuck on updating a bean.
I have the following save function within a class for each bean:

public function save(){
global $redbean;
global $rb_adapter;

$this->id = R::store($this->video);

return $this->id;
}

The page is either blank or retrieves a bean like this:

$video = new Video($videoId);

collects the values from the form like this:

$video->title = $_POST["title"];
$video->date_created = $_POST["date_created"];

and saves them like this:

$video->save();

If there is no bean, then save creates a new one, but does not populate any of the fields.

If it does have a $videoId then nothing updates.

Any help would be very gratefully received. 

Thank you



Message has been deleted

Benoit Pruneau

unread,
Jun 28, 2022, 10:01:41 AM6/28/22
to redbeanphp
You must use :
$video = R::load('video', $videoId);
to create a bean. The Video class is the Model the bean will use. See https://redbeanphp.com/index.php?p=/models

Often, I use the phpdoc notation to clarify this to my IDE:

/** @var \Model\Video|OODBBean $video */
$video = R::load('video',$videoId);
Reply all
Reply to author
Forward
0 new messages