Jump to content

Recommended Posts

Posted

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

Posted

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)

Posted

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) 

 

Posted

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.

  • Like 3
  • Thanks 1
Posted
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!!

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
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...