The following warnings occurred: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Warning [2] Undefined property: MyLanguage::$archive_pages - Line: 2 - File: printthread.php(287) : eval()'d code PHP 8.1.31 (Linux)
|
ItemManager 2.0 - Printable Version +- GetSimple Support Forum (http://get-simple.info/forums) +-- Forum: GetSimple (http://get-simple.info/forums/forumdisplay.php?fid=3) +--- Forum: Plugins (http://get-simple.info/forums/forumdisplay.php?fid=13) +--- Thread: ItemManager 2.0 (/showthread.php?tid=7293) |
RE: ItemManager 2.0 - Bigin - 2019-01-24 Ok thx. (2019-01-24, 23:14:52)PGK37 Wrote: I do not know, it looks like they changed when I uploaded to the server. Nothing here changes on its own... First you have to determine if the item ID's on the hosts are identical or not. I guess that's the problem. Run some tests:
RE: ItemManager 2.0 - PGK37 - 2019-01-25 (2019-01-24, 23:44:29)Bigin Wrote: Ok thx. Thanks for your feedback. Do I have to delete the data sides OVH and LOCALHOST and add a new element on both sides to make this comparison? RE: ItemManager 2.0 - PGK37 - 2019-01-25 I deleted the data on both sides and created elements. The IDs seem to be identical. The problem arises as soon as a photo is added it seems RE: ItemManager 2.0 - Bigin - 2019-01-25 Then look at GS log file, there you will find the problem RE: ItemManager 2.0 - Felix - 2020-04-25 Hi Bigin, I just came across ItemManager and IM Extra Fields. I want to personally thank you for creating ItemManager and IM Extra Fields for GS. These are amazing applications and make any sort of website possible. F. RE: ItemManager 2.0 - Bigin - 2020-04-25 Hello Felix, thank you for your interest in ItemManager, enjoy using it! ;-) RE: ItemManager 2.0 - Felix - 2020-04-26 Hi, I just started to begin to use the ItemManager. I have put this code from an example in the top of template.php from the Innovation theme: Code: <?php Then I want to output in the template.php from the Innovation theme like this: Code: <?php But Hello world is not outputted. What am I doing wrong ? RE: ItemManager 2.0 - Bigin - 2020-04-26 Hi Felix, you probably have not created a category yet? Are you a bit familiar with MySQL databases? So you could see it that way: 1. A category is similar to a table in the database. 2. A category is assigned different fields. Fields are the columns in your table. 3. And the items are the datasets. To be able to create your datasets (items), you will first create a table (category) with columns (fields). Try ItemManager v3 the API is much easier to get familiar with it: https://im.ehret-studio.com/tuts/itemmanager-simple-flat-file-cmf/common-information/ RE: ItemManager 2.0 - Felix - 2020-04-26 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. RE: ItemManager 2.0 - Bigin - 2020-04-26 Hi, you're almost doing it right. This is your mistake: PHP Code: echo $item->text; The main difficulty with IM2 is that there are 2 types of item-object. The first one is native "Item" object and the second one is "SimpleItem" object - this can be really confusing... It's better to use native "Item" object only if you intend to modify an item, e.g. to store a value in an item field, etc. But if you want to just view the items, you should rather use the "SimpleItem" object. So let's get back to your problem. With this method you select an "Item" object, but access the "text" field as if it were a SimpleItem object: PHP Code: $item = $imanager->getItem(1, 2155046657); // $item is an "Item" object If you want to access an "Item" object field value, you have to do it this way: PHP Code: echo $item->fields->text->value In the case above, you don't want to have "write" access to the item, you only want to show the value of a field. That' s why it is better to use SimpleItem object in this case. To be able to operate with SimpleItem objects, you should use the ItemMapper class. ItemMapper - is a class that allows you to work with Items e.g. to select, sort or filter them: PHP Code: $imanager = imanager(); To be able to work with the items of a category with ID 1, you have to load them into the memory first, you can do this as follows: PHP Code: $itemMapper->alloc(1); Now, the items of your category are loaded in memory. To select your item (SimpleItem) with the ID 2155046657, do the following: PHP Code: $SimpleItem = $itemMapper->getSimpleItem(2155046657); You can access the value of an SimpleItem object as follows: PHP Code: echo $SimpleItem->text; Your example here should work. Check again the ID's. Check under "Admin" > "Manager" > "Items", whether an item was created: PHP Code: $imanager = imanager(); Hope that helps you a little. RE: ItemManager 2.0 - Felix - 2020-04-27 Hi Bigin, Thanks a lot for your reply and clear explanation about the difference between "Item" object and "SimpleItem" object. I followed your instruction and replaced my code with: Code: echo $item->fields->text->value And immediately I have my code working here: Code: <?php Thanks again, I start to understand it better now Although I used $itemMapper->init(2); instead of $itemMapper->alloc(2); Is there a difference between init and alloc ? RE: ItemManager 2.0 - Bigin - 2020-04-27 Hi Felix, yeah there is a difference. This is the method for loading the SimpleItem objects of a specific category into memory. There is only this one method: PHP Code: $itemMapper->alloc($category->id); To load the items of type "Item" object, there are a lot of various methods. This allows you to manage the available memory more efficiently, e.g. to avoid loading all items of a category into memory at once. This can be very helpful, when creating pagination for a large number of items. PHP Code: $itemMapper->quickInit($category->id[, $fields, $start, $bulk, $pat]); RE: ItemManager 2.0 - Felix - 2020-04-27 Hi Bigin, Thanks for your reply and explaining the various methods how to load the items of type "Item" object And yes, like you mentioned, I can confirm that this code is now working also: Code: $imanager = imanager(); I believe that the word 'data' in the example above is used as a reference to a field type e.g. a text field and that data is not a field type by it self. But maybe this is already something obvious to know. But I am not sure about that because I have seen this somewhere also: $item->fields->color->value and color is not listed in the list of available field types. I use the code above like this now with success: Code: $imanager = imanager(); When I go to back end admin => Manager => View All => Category1 => on the bottom of the page I can see that the new item has been created. F. RE: ItemManager 2.0 - Bigin - 2020-04-27 Just FYI: The Item object method setFieldValue() is used to populate the field value appropriate to its concept. The method can contain 3 parameters: Code: setFieldValue($field_name, $field_value[, $sanitize]) (mixed) $field_name - is the name of the field which value should be filled. (mixed) $field_value - is the field value. (boolean) $sanitize (optional) - is a flag that can be used to sanitize the passed $field_value according to the field concept. This value is set to "true" by default. For example, to set a value of the field of type "text" with the name "content", you can use the method as follows: PHP Code: $item->setFieldValue('content', 'bla-<script>alert("XSS")</script>'); it echoes: bla-alert("XSS") Because sanitize flag is set to "true" by default and it removes any HTML. Another example. If you have set the minimum length of 20 characters for the field content (under IM field details): PHP Code: $item->setFieldValue('content', 'bla-bla'); This method returns "false" and the value "bla-bla" will not set because it is shorter than 20 characters. To find out why the method does not have the value set you can check the error code: PHP Code: if(!$item->setFieldValue('email', 'bla-bla')) { Here you can get a list of error codes: https://ehret-studio.com/articles/itemmanager/itemmanager-2-api-reference-working-with-items/ If you do not want to sanitize the value, you can set the $sanitize flag to false: PHP Code: if(!$item->setFieldValue('content', '<script>alert("XSS")</script>', false)) { RE: ItemManager 2.0 - Felix - 2020-04-27 Hi Bigin, Thanks for explaining more about setFieldValue() and the list with errors. I found there also the api reference for items and categories. Also I found scriptor based on ItemManager. ItemManager is really powerful with a wide range of applications. I think it is also the solution for a hidden page to manage other pages. See posts #5 and #6 in this thread: http://get-simple.info/forums/showthread.php?tid=13857 RE: ItemManager 2.0 - Felix - 2020-04-28 What is the minimum PHP version for ItemManager version 2 - GS plugin ? RE: ItemManager 2.0 - Bigin - 2020-04-28 I guess it needs to be a minimum of 5.6 ... maybe 5.4 would do, not tested. PHP7 + is recommended. RE: ItemManager 2.0 - Felix - 2020-04-28 Hi, For some reason I don't manage to echo an image on the front end. I have only 1 image with the image name laptop.png inside: Category id=1 Category name = HomeCategory Item id = 1 Item name = first_home_item field name = image (File upload field) I searched the ItemManager thread and this is what I found how to echo an image on the front end: Code: echo '<img alt="" src="'. htmlspecialchars($item->fields->image->imagefullurl[0]). '" width="200" >'; But the image laptop.png does not appear on the front. What am I doing wrong ? RE: ItemManager 2.0 - Bigin - 2020-04-28 It should be: PHP Code: $item->fields->image->fullurl[0] You may also want to use Sanitizer's url() method: PHP Code: $url = IM_SITE_URL.$imanager->sanitizer->url($item->fields->image->fullurl[0]); RE: ItemManager 2.0 - Felix - 2020-04-28 Hi Bigin, Yes now I have it working, thanks for helping out. The image is finally published on the front end ! I didn't even know about IM_SITE_URL, are there more of those ? RE: ItemManager 2.0 - Bigin - 2020-04-28 Here you will find the IM constants: plugins/imanager/lib/inc/_def.php By the way, you can also use following function to modify the images. It returns an image url sized/cropped to the specified dimensions: PHP Code: /** Note that you must pass a SimpleItem as the first parameter. RE: ItemManager 2.0 - Felix - 2020-04-28 Hi, I found following code in the thread what comes handy for debugging purposes: Code: foreach($your_item->fields->image->imagename as $imagename) { However, this part does not seem to output anything: $your_item->fields->image->imagename Is imagename still a valid part of ItemManager version 2 ? RE: ItemManager 2.0 - Bigin - 2020-04-28 Hello, image_name is an image field property, this is deprecated and no longer available. There are available properties for the FileUpload field (excluding of the default field properties): 1. file_name 2. path 3. fullpath 4. url 5. fullurl 6. title You can check this with: PHP Code: Util::preformat($item->fields->image); RE: ItemManager 2.0 - Felix - 2020-04-28 Hi, Thanks for showing the IM constants and the available FileUpload field properties. Util::preformat($item->fields->image); is also super cool for debugging. With this info I could debug my faulty code and now have everything working. = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = Fun fact is that echo '<img alt="" src="'. $my_item->fields->image->fullurl[0] .'" width="100" >' is working on the home page but not on the about page On the about page I have to add IM_SITE_URL to make the image show on the front echo '<img alt="" src="'. IM_SITE_URL . $my_item->fields->image->fullurl[0] .'" width="100" >'; // this is working ! Maybe this has something to do with the Innovation theme or maybe Laragon local server that I am using. Anyway, IM_SITE_URL is really very handy to use. = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = I had a look at ItemManager v3 but it does not seem to have a visual GUI. I guess it was designed to use it programatically. Advantage is that it makes it independent of a CMS and can use it anywhere as a php include. What I like about ItemManager v2 as a plugin for GS is the visual GUI under the Manager Tab in the GS backend. The visual GUI makes it easy. RE: ItemManager 2.0 - Bigin - 2020-04-28 Hello Felix, yes you are right, it has no GUI by default. But it has a much more powerful and simple API, it scales well and has 10x better performance than IM2. It would also be a great challenge for someone who wants to discover the new API to write a plugin for GetSimple that provides a simple GUI for ItemManager3? ;-) Anyway, I hope you enjoy IM whether 2 or 3 :-) |