Jump to content
Sign in to follow this  
Manol

Profields table

Recommended Posts

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

Share this post


Link to post
Share on other sites

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)

Share this post


Link to post
Share on other sites

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) 

 

Share this post


Link to post
Share on other sites

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 2
  • Thanks 1

Share this post


Link to post
Share on other sites
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!!

Share this post


Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

×
×
  • Create New...