2020-04-26, 19:45:03
Hi Bigin,
Thanks for your reply,
Yes I read about ItemManager v3 but I want to learn everything about ItemManager v2 first
because it integrates so nicely with GS.
What I did:
I added your helper function in the Theme file functions.php
function get_page_item($category_id) {
$imanager = imanager();
$mapper = $imanager->getItemMapper();
$mapper->alloc($category_id);
$pageId = Util::computeUnsignedCRC32(return_page_slug());
return $mapper->getSimpleItem($pageId);
}
Then I added this test code to the Theme template file template.php
<?php
$item = get_page_item(1);
if($item) {
echo "<h3>$item->name</h3>";
echo $item->text;
}
?>
Now the contents of the fields name and text are published on the page,
this is great, my first successful steps into ItemManager !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I still have problems getting field contents published on a page
without the helper function when I try to use this way:
$imanager = imanager();
// to get a specific item by "category id" and "item id" use
$item = $imanager->getItem(1, 2155046657);
echo "<h3>$item->name</h3>";
echo $item->text;
What am I missing here ? Do I have to use here also:
$imanager = imanager();
$mapper = $imanager->getItemMapper();
$mapper->alloc($category_id);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I have created a category, fields and added contents to the fields
when I edit a page. So far so good.
However following this example still does not work for me:
$imanager = imanager();
$item = new Item(1);
$item->name = 'My item name';
$item->setFieldValue('data', 'Hello world');
$item->save();
In order to bring the data into display again do this:
$item = imanager()->getItem(1, 'name=My item name');
echo $item->fields->data->value; // Outputs: Hello world
What am I missing here ? Do I have to use here also:
$imanager = imanager();
$mapper = $imanager->getItemMapper();
$mapper->alloc($category_id);
Thanks in advance,
F.
Thanks for your reply,
Yes I read about ItemManager v3 but I want to learn everything about ItemManager v2 first
because it integrates so nicely with GS.
What I did:
I added your helper function in the Theme file functions.php
function get_page_item($category_id) {
$imanager = imanager();
$mapper = $imanager->getItemMapper();
$mapper->alloc($category_id);
$pageId = Util::computeUnsignedCRC32(return_page_slug());
return $mapper->getSimpleItem($pageId);
}
Then I added this test code to the Theme template file template.php
<?php
$item = get_page_item(1);
if($item) {
echo "<h3>$item->name</h3>";
echo $item->text;
}
?>
Now the contents of the fields name and text are published on the page,
this is great, my first successful steps into ItemManager !
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I still have problems getting field contents published on a page
without the helper function when I try to use this way:
$imanager = imanager();
// to get a specific item by "category id" and "item id" use
$item = $imanager->getItem(1, 2155046657);
echo "<h3>$item->name</h3>";
echo $item->text;
What am I missing here ? Do I have to use here also:
$imanager = imanager();
$mapper = $imanager->getItemMapper();
$mapper->alloc($category_id);
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
I have created a category, fields and added contents to the fields
when I edit a page. So far so good.
However following this example still does not work for me:
$imanager = imanager();
$item = new Item(1);
$item->name = 'My item name';
$item->setFieldValue('data', 'Hello world');
$item->save();
In order to bring the data into display again do this:
$item = imanager()->getItem(1, 'name=My item name');
echo $item->fields->data->value; // Outputs: Hello world
What am I missing here ? Do I have to use here also:
$imanager = imanager();
$mapper = $imanager->getItemMapper();
$mapper->alloc($category_id);
Thanks in advance,
F.