Few Questions about Modules

edited January 2012 in Modules
Is there anyway to show parent Child relationship in the admin? I've created a simple module and I've gone as far as creating a custom one, but I want to show a parent child relationship rather than a 1:1.

I'd like to achieve something were I can look at a category see all the products, click on a product and get the edit screen, or have an option to create a new product under that category.

I cant figure out how to pull it all together. The simple module works great by establishing foreign keys etc, but not practical when looking a several hundred products and trying to determine if one already exists.

Thanks
Matt

Comments

  • edited 9:08PM
    If you are referring to the left side menu, it currently only allows you to group menu items and not nest any further.

    If you referring to something similar to the "Tree' button when viewing pages, navigation, or blog posts, there is a tree method you can add to your model.

    You could also set up your categories form to list all your products listed in a multi select so when you go to edit a category, you can view and associate products with it as well.
  • edited 9:08PM
    For the second option of creation, not tried but you could write a custom button for the list items.

    Could also use a custom form field type in the category edit screen to bring all of its products through. It's a extra click but has the benefit of being filtered by category already.
  • edited 9:08PM
    Yeah I was kind of thinking if I was looking at category, I could click a link in the row that would show all products under cat. And their would be option to edit/ create new products under category.
    Right now my module goes straight to form when I click the row. I'm confused about how I tie a method get products to my category module in the framework.

    Example if you look at the blog example it only shows a 1:1 relationship. Blog posts have categories but I cant figure out how to view all posts w/ category x.
  • edited 9:08PM
    Just to be clear, by row you mean a row in the list items table?

    I'm on my phone atm.. If you want a custom table action there take a look in the /modules/fuel/config/fuel_modules.php file. There's some good examples in there that might help.

    If you wanted to do it in the edit screen of your categories you could have a custom 'item_actions' button.

    Another way would be to do Dave suggested with the multi combo boxes, can have an add button to the right of those.

    Yet another way, in the form_fields method of your categories controller, have a custom field/func to bring the related products through.

    Another way that doesn't work how you want though would be to do this on the products. Products table can have the related category display in each row. Those rows can be filtered an ordered. This would require the least amount of work.

    That's probably difficult to understand without examples I know.
  • edited 9:08PM
    @Lance, Yes, I'm talking about the list items table. Everything works like a charm in the CRUD arena, but I just would like to display a parent child relationship inside of an admin view.

    I'll look at the modules/fuel/config/fuel_modules.php file.
  • edited 9:08PM
    Lance & Admin -

    Thanks for your help. customized the list view to pull in the category, so i know list all the products with the category in the list view. I can group them as Lance pointed out, and it was pretty simple.

    Thanks.
    Matt
  • edited 9:08PM
    Quick question, the list_items method I customized isnt working anymore, if I do a print_r($data) I can see the result set, but there is no table generated.

    I cant figure out what is going on. What is the best way to debug this process.

    thanks
    matt
  • edited 9:08PM
    The thing about this issue is that the paging looks to be building the right amount of pages.
    My query is right, because I can execute $this->db->debug_query(); and get the expected result.
  • edited 9:08PM
    Is the result set an array of arrays (instead of an array of objects)?
  • edited 9:08PM
    Yeah, its exactly like my other models, but I am defining a custom list_items method.

    do you know what's happening?
  • edited 9:08PM
    Can you post the method? What does Firebug have to say?
  • edited 9:08PM
    Lance not sure I understand your question, the data is coming out looking like this.
    Array ( [0] => Array ( [id] => 357 [cname] => Sports [pname] => Basketball [type] => Indoor ) [1] => Array ( [id] => 382 [cname] => Sports [pname] => MMA Gloves [type] => Indoor ) [2] => Array ...

    function list_items($limit = NULL, $offset = NULL, $col = 'category.name', $order = 'asc')
    {
    $this->db->join('category', 'category.id = product.category_id', 'left');
    $this->db->join('type', 'type.id = product.type_id', 'left');
    $this->db->select('product.id, category.name AS cname, product.name as pname,type', FALSE);

    $data = parent::list_items($limit, $offset, $col, $order);
    return $data;
    }
    Admin seems to think it's because they are not objects?
    Matt
  • edited January 2012
    It's meant to be array's as far as I can see in base_module_model::list_items. Probably just checking it wasn't objects.

    This is in a model for products where the table name is 'product' right?

    Can you check the output in FireBug (Net->XHR). It can just show the spinning gif if there's an error in there some where
  • edited 9:08PM
    lance - I get 200 status: 88.3 kb. There are not problems with the sql output because like i said it is paging.

    It was working on friday and then something happened, but I dont know what. If I remove my list_items function the data comes through, so I know it's not a database data issue.

    Event if I print_r in the list_items function in the Base_module I get the data. It's like it's not calling the view for some reason.
  • edited 9:08PM
    You are just seeing the spinning gif yes?

    We're not trying to check the sql etc. If you check the response panel in Firebugs Net->XHR you'll see any errors there. Otherwise you'll see a swag of html to build the table.

    The pagination is somewhat separated from the actual list.
  • edited 9:08PM
    oh I see now sorry, I'm a chrome user :) anyhow yeah, saying the name is ambiguous, but as you can tell from my method above, I specify tablename.name for the sort criteria.

    A Database Error Occurred

    Error Number: 1052

    Column 'name' in order clause is ambiguous

    SELECT product.id, category.name AS cname, product.name as pname, type
    FROM (product)
    LEFT JOIN category ON category.id = product.category_id
    LEFT JOIN type ON type.id = product.type_id
    ORDER BY name asc

  • edited 9:08PM
    Filename: /web/fuel/modules/fuel/models/base_module_model.php

    Line Number: 236

  • edited 9:08PM
    Hmm.. can you click the refresh icon to the left of the filter input on the list view.

    Long shot but if you had a filter in play then changed something, it can cause problems.
  • edited 9:08PM
    Well I sorted it out, maybe it was user error and I was not communicating it clearly.
    Based on the tutorial on simple module, I just followed the flow and left my function pretty much as demonstrated.
    $data = parent::list_items($limit, $offset, $col, $order);
    but I had to change it to this
    $data = parent::list_items($limit, $offset, 'product.name' , $order);

    and now it's all better.
  • edited 9:08PM
    Glad you got it sorted. Still, seems odd.

    Is your module config 'default_col' just 'name'? If so, I'd say that was overwriting it.
  • edited 9:08PM
    it's not specified.
  • edited 9:08PM
    Ah looks like it defaults to display_field on line #362 of the module controller in that case.
Sign In or Register to comment.