Few Questions about 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
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.
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.
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.
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.
I'll look at the modules/fuel/config/fuel_modules.php file.
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
I cant figure out what is going on. What is the best way to debug this process.
thanks
matt
My query is right, because I can execute $this->db->debug_query(); and get the expected result.
do you know what's happening?
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
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
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.
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.
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
Line Number: 236
Long shot but if you had a filter in play then changed something, it can cause problems.
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.
Is your module config 'default_col' just 'name'? If so, I'd say that was overwriting it.