⚠ In case you've missed it, we have migrated to our new website, with a brand new forum. For more details about the migration you can read our blog post for website migration. This is an archived forum. ⚠

  •     

profile picture

Creating breadcrumbs in grocery crud



jrox

jrox
  • profile picture
  • Member

Posted 17 May 2015 - 16:12 PM

I've been trying serveral approaches to implement basic breadcrumbs links at the top of my page but failed to get it to work.

 

Think of my data model as this:

 

country -> area -> city

 

I've added a custom action button on the rows of the country view which links to the area view and filters (where) automatically on the country selected by country_id. Now I would like to display the country name at the top of the screen so the user knows which country he has selected. The same should happen from the area view going on to the city table.

 

Going from country to area all I have is the country_id which is passed to the controller but I don't have the country_name. I've tried storing the country_name in the custom add_action callback but that doesn't work since the add_action callback is called on load and not on click.

 

Any ideas how I can get this to work without having to code my own application?

 

Thanks

Jimmy


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 22 May 2015 - 02:32 AM

i had done it in past - need to scan out the codes and update but its quite possible..

what you need to do is manage the breadcum generation yourself

post that u can just add the code in the crud (view) to show the same.


Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 02 June 2015 - 11:58 AM

Hi guys! This is how i do:
 

class Countries {


public $breadcrumbs = array();


....constructor


public function index()
{
    
    $this->breadcrumbs['link_to_main_admin_page'] = link_name;
    $this->breadcrumbs['countries_controller'] = countries_link_name;

    if(we have primary key) 
    {
      get name of country - quering table "countires"
      $this->breadcrumbs['admin/countries/index/edit/{primary_key}'] = country_name;
    }

    $crud->table = 'countries';

    ...other stuff

//    add action area
    $crud->add_action('admin/countries/area',....);

}

public function area($country_id)
{
    //here get all breadcrumbs we need
    $this->breadcrumbs['link_to_main_admin_page'] = link_name;
    $this->breadcrumbs['countries_controller'] = countries_link_name;
    
    if($country_id)
    {
      //get country name - quering table 'countries' by $country_id
      $country_obj = ....
      $this->breadcrumbs["admin/countries/index/edit/$country_id"] = $country_obj->name;
    }

    if(we have primary key) 
    {
      get name of area - quering table "areas"
      $this->breadcrumbs['admin/countries/area/$country_id/edit/{primary_key}'] = area_name;
    }

    $crud->table = 'areas';

    //same add action for city and repeat all actions 
    $crud->add_action("admin/countries/area/$county_id",....);
}

public function city($country_id, $area_id)
{
   //repeat action like in area method
}

}

Then $breadcrumbs send to the view you need and show breadcrumbs with foreach

Code have mistakes but this is just the picture of how to achieve this functionality, do not just copy paste! :)

Hope it clear


Amit Shah

Amit Shah
  • profile picture
  • Member

Posted 02 June 2015 - 17:25 PM

Thanks Paul - good to see you in action ... atleast someone have been active enough to solve the issues - sorry i have been too occupied with the work i am into now a days :( ...

but good to see you around... Happy GCing :)


Paul Savostin

Paul Savostin
  • profile picture
  • Member

Posted 03 June 2015 - 10:04 AM

Hi! Nice to see you Amit too :)  Thanks! Will be free minute I'll help people here if I can