Manol Posted May 24, 2018 Posted May 24, 2018 Hello. I've a protable with fields: name(text) notes(textarea) How can I add a new row and populate the fields?. $test = $page->protabla->getNew(); $test->name = 'my name'; $test->notes = 'my note'; $test->save(); Thanks
Autofahrn Posted May 24, 2018 Posted May 24, 2018 did you save the page afterwards? $test = $page->protabla->getNew(); $page->of(false); // always a good idea $test->name = 'my name'; $test->notes = 'my note'; $test->save(); $page->save('protabla'); // only save that field $page->of(true); (only guessing)
Manol Posted May 24, 2018 Author Posted May 24, 2018 It gives the following error: Error: Uncaught Error: Call to a member function save() on array in /......php:180 Stack trace: #0 /wire/core/TemplateFile.php(287): require() #1 //wire/core/Wire.php(380): ProcessWire\TemplateFile->___render() #2 /wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___render', Array) #3 //wire/core/Wire.php(442): ProcessWire\WireHooks->runHooks(Object(ProcessWire\TemplateFile), 'render', Array) #4 //wire/modules/PageRender.module(514): ProcessWire\Wire->__call('render', Array) #5 //wire/core/Wire.php(383): ProcessWire\PageRender->___renderPage(Object(ProcessWire\HookEvent)) #6 //wire/core/WireHooks.php(723): ProcessWire\Wire->_callMethod('___renderPage', Array) #7 //wire/core/Wire.php(442): ProcessWire\WireHoo (línea 180 de ....n.php)
Autofahrn Posted May 24, 2018 Posted May 24, 2018 and line 180 is which one? I'll setup a test and come back...
Autofahrn Posted May 24, 2018 Posted May 24, 2018 Try this: $test = $page->protabla->makeBlankItem(); // getNew(); is wrong, allocation done by makeBlankItem() $page->of(false); // always a good idea $test->name = date('D, d M Y H:i:s'); $test->notes = 'my note'; // $test->save(); // not required $page->protabla->add($test); $page->save('protabla'); // only save that field $page->of(true); functional test code (with delayed output) here: <?php namespace ProcessWire; $test = $page->protabla->makeBlankItem(); $page->of(false); // always a good idea $test->name = date('D, d M Y H:i:s'); $test->notes = 'my note'; $page->protabla->add($test); $page->save('protabla'); // only save that field $page->of(true); $content = "<h4>{$page->title}</h4>"; $content .= "<table>"; foreach($page->protabla as $pt) { $content .= "<tr><td>{$pt->name}</td><td>{$pt->notes}</td></tr>"; } $content .= "</table>"; Edit: Maybe this should be moved to the ProFields Table support forum. 3 1
Manol Posted May 24, 2018 Author Posted May 24, 2018 22 minutes ago, Autofahrn said: Try this: $test = $page->protabla->makeBlankItem(); // getNew(); is wrong, allocation done by makeBlankItem() $page->of(false); // always a good idea $test->name = date('D, d M Y H:i:s'); $test->notes = 'my note'; // $test->save(); // not required $page->protabla->add($test); $page->save('protabla'); // only save that field $page->of(true); functional test code (with delayed output) here: <?php namespace ProcessWire; $test = $page->protabla->makeBlankItem(); $page->of(false); // always a good idea $test->name = date('D, d M Y H:i:s'); $test->notes = 'my note'; $page->protabla->add($test); $page->save('protabla'); // only save that field $page->of(true); $content = "<h4>{$page->title}</h4>"; $content .= "<table>"; foreach($page->protabla as $pt) { $content .= "<tr><td>{$pt->name}</td><td>{$pt->notes}</td></tr>"; } $content .= "</table>"; Edit: Maybe this should be moved to the ProFields Table support forum. Awesome!!
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