parent controller detection in block
In a v1 install, I have a breadcrumb block that will need to deliver the CMS trail if the main layout / CMS controller is the parent, but a module product trail if called from MY_ controller.
What's the best way to achieve this? At the moment I have set a property in MY_Controller, and any view using that controller will detect it and use the product trail, rendered from a custom library - otherwise it uses the CMS fuel_nav() method. But I'm thinking there is probably a "Fuel Way" I've not considered. Is there a simple Fuel property or method to use to determine if the parent view, layout or controller is CMS driven?
Comments
$product = fuel_nav('products', array('find' => 'one', 'where' => array('category_id' => uri_segment(2), 'product); $productnav['products'] = 'Products'; $productnav['products/'.$product->category_name] = array('label' => $product->category_name, 'parent_id' => 'products'); $productnav['products/'.$product->category_name.'/'.$product->slug] = array('label' => 'Product Name', 'parent_id' => 'products/'. $product->category_name);
$append['products/my_category'] = array('label' => 'My Category', 'parent_id' => 'products'); $append['products/my_category/my_product'] = array('label' => 'My Product', 'parent_id' => 'products/my_cateogry');
NOTE: parent_id values will need to use the database "id" value if using the CMS
My issue was
1) There was a gap in the urls - eg a list page might be:
/products/category/automotive/auto-accessories
& a product item like
products/category/automotive/auto-accessories/item/1587
so there was a parent->child void. Once I'd fabricated that and...
2) I forgot, omitted to use the "active" argument in the menu class eg:
$this->menu->render_breadcrumb($nav, $current_url)
it all works OK!!
echo fuel_nav( array( 'file' => $this->uri->segment(1), 'var' => 'nav', 'active' => uri_path(), 'append' => array(array( 'label' => 'Some label', 'location' => 'go/there' )) ) );
which combines a _variables file named the same as the root url segment with the appended value - a nested array.
In another menu, I needed to have hard-coded vars as well as CMS navigation. I just used 2 fuel_nav(), but would there be a way of using append to make just one list?
I tried using append and making its array a return_normalized fuel_nav(). But that didn't seem to work.
$append['products/my_category'] = array('label' => 'My Category', 'parent_id' => 'products'); $append['products/my_category/my_product'] = array('label' => 'My Product', 'parent_id' => 'products/my_cateogry');
If pulling from the database, those unique values are the database ID value. So the parent_id needs to reflect that value if necessary.
Regarding your questions about using append instead of 2 fuel_nav function calls, I would think that would be append would be a good alternative.