New item details not showing

alt=
@dobmat
10 years ago
93 posts
I have created a module which shows up on profile page of users (like jrBlog) and allows to add new entries. But the new entry details is not shown if I click on it even though the URL is pointing to that particular item. Instead it shows all the created items. Which template controls the view for that. I have item_detail.tpl in the module but it still used item_list.tpl I think. Please help.

Thanks
updated by @dobmat: 05/16/14 08:13:13AM
brian
@brian
10 years ago
10,148 posts
It should use item_detail.tpl - make sure you are constructing the URL correctly to the item - it should be in the format:

jrCore_base_url / profile_url / module_url / item_id / item_title_url

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
alt=
@dobmat
10 years ago
93 posts
The URL is correct as you have stated. Please see the attached screen shots where URL can be seen at the bottom left corner. I tested it with putting a {debug} in item_detail.tpl file and I don't get the smarty console.
test.png
test.png  •  112KB


updated by @dobmat: 04/11/14 08:54:09AM
brian
@brian
10 years ago
10,148 posts
Do you have a profile.php file in your module? If you do, rename or remove it. Sounds like there is a profile.php router taking over and it is not setup.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
alt=
@dobmat
10 years ago
93 posts
Yes, I have a profile.php in my module. But if I remove it then new items created will not be displayed which is what I want. My profile.php is as attached. My create form has only 2 fields, venue name and image. I want all the items to be displayed under the module tab and when click on the item it should show item details. Please suggest how I can achieve this.

Thanks.
code.png
code.png  •  25KB


updated by @dobmat: 04/14/14 04:06:42AM
brian
@brian
10 years ago
10,148 posts
The problem here is that you are only handling 1 condition in your "default" profile view. When a module has a profile.php file, then ALL requests for that module in a profile - i.e.

yoursite.com/profile_url/module/*

are going to be routed through your "default" view.

So in your view here you need to check to see if $_post['_1'] is numeric - if it is, you need to show the item_detail.tpl file instead of item_list.tpl - i.e.

if isset($_post['_1']) && jrCore_checktype($_post['_1'], 'number_nz')) {
    $_it = jrCore_db_get_item('ModuleDir', $_post['_1']);
    return jrCore_parse_template('item_detail.tpl', $_it, 'ModuleDir');
}
else {
    .. what you already have ...
}

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
alt=
@dobmat
10 years ago
93 posts
I'm able to redirect to item_detail.tpl now. But on item detail page I'm getting exceptions,
jrCore_item_detail_buttons: invalid item array received
jrImage_display: image item_id parameter required
jrCore_item_detail_features: invalid item array received

I tried to modify the code that you gave by using jrCore_db_search_items function to get all details of the item. I can see in the smarty console that the contents of the items are there. But I still get the same exception. Please help.

Thanks.
Screenshot-2.png
Screenshot-2.png  •  47KB


updated by @dobmat: 04/15/14 02:39:24AM
brian
@brian
10 years ago
10,148 posts
Near the top of your custom module you should have a call like this:

{jrCore_item_detail_buttons module="gsVenue" field="venue_file" item=$item}

Note that "venue_file" needs to be the field name of the file you allow to be uploaded when creating/updating one of your items - if you don't allow a file, remove the field param.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
alt=
@dobmat
10 years ago
93 posts
Do you mean to say that if I have for e.g. a image file uploaded during item creation I need to have the "field" in my template code?

Thanks.
brian
@brian
10 years ago
10,148 posts
dobmat:
Do you mean to say that if I have for e.g. a image file uploaded during item creation I need to have the "field" in my template code?

Thanks.

No - not for an image, say if you were allowing an audio file, video file, etc. to be uploaded.

Remove it for now just to be sure things are working.


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net
alt=
@dobmat
10 years ago
93 posts
I don't have that line "field" in my template code. I see in the smarty console that there is no array $item but what is there is $_items. is that what I need to use?

Thanks.
updated by @dobmat: 04/15/14 07:18:41AM
brian
@brian
10 years ago
10,148 posts
dobmat:
I don't have that line "field" in my template code. I see in the smarty console that there is no array $item but what is there is $_items. is that what I need to use?

Thanks.

No - you should not see $_items - you should see $item. $_items will only be set for your item_list.tpl file. I think it's important to take a step back here and try to understand what you are actually doing - without understanding what you are doing you're just going to be operating in a 100% "reactive" mode where you are making changes to things without understanding why you are doing them.

In your profile.php file now, there should be 2 different jrCore_parse_template calls - one to "item_list.tpl" and one to "item_detail.tpl".

item_list.tpl - this is the template that is used when you are displaying a list of items from the module. It will contain a smarty foreach loop where it loops over the $_items array - for each entry in the $_items array it will process the inside of the foreach loop one time. This is how we create a "list".

The way that the $_items array is built is by a call to jrCore_db_search_items() - this is the DataStore function that is used to get multiple items, and order them, etc.

item_detail.tpl - this template is used to display the information for a single item - not a list of items. There will be no foreach loop inside this template, and the data for the item will be in the $item array - not $_items (since there is only a single entry). The information for a single item is pulled from the DataStore using jrCore_db_get_item() - since we know the item_id we do not have to use the search function.

Since you are seeing an $_items array in your item_detail.tpl file, you are using the wrong datastore function to get the item.

The most simple profile.php "default" view should look something like this:

if (isset($_post['_1']) && jrCore_checktype($_post['_1'], 'number_nz')) {
    $_rp = array();
    $_rp['item'] = jrCore_db_get_item('module_dir', $_post['_1']);
    return jrCore_parse_template('item_detail.tpl', $_rp, 'module_dir');
}
else {
    $_sc = array(
        'limit' => 10
    );
    $_rp = jrCore_db_search_items('module', $_sc);
    return jrCore_parse_template('item_list.tpl', $_rp, 'module_dir');
}

Remember this is the most simple profile router, and somethings to note:

1) we create an array called $_rp (replacement) that we pass into jrCore_parse_template - the keys and values of this array are way are going to be available to us in our template. When we are processing our item_detail.tpl, see how we assign the returned array to the "item" key? This means the item information will be part of the $item variable inside the template.

2). jrCore_db_search_items() takes an array of parameters for it's second argument - you will need to flush that out to suit your needs.

Spend some time testing and playing around with this so you get an idea of how things work - that will allow you to move forward a better pace when you understand how the profile routing works.

Hope this helps!


--
Brian Johnson
Founder and Lead Developer - Jamroom
https://www.jamroom.net

updated by @brian: 04/15/14 07:56:51AM
alt=
@dobmat
10 years ago
93 posts
Thanks a lot for the detailed information. I'm working on a tight schedule and new to Jamroom which is why I'm having to use what ever information I can get and try to tailor it to my requirements.

Thanks.

Tags