Skip to content

Latest commit

 

History

History
114 lines (89 loc) · 2.24 KB

php_configuration.md

File metadata and controls

114 lines (89 loc) · 2.24 KB

PHP configuration

Add breadcumbs to the trail with PHP in your controller.

Basic example

/**
 * @Breadcrumb("Level 1")
 * @Breadcrumb("Level 2")
 */
class MyController extends Controller
{
    /**
     * @Breadcrumb("Level 3")
     */
    public function myAction()
    {
        $this->get("apy_breadcrumb_trail")->add('Level 4');
    }
}

Will render the following breadcrumb trail :

Level 1 > Level 2 > Level 3 > Level 4

Reference

$this->get("apy_breadcrumb_trail")->add(
    $breadcrumb_or_title,
    $routeName,
    $routeParameters,
    $routeAbsolute,
    $position,
    $attributes
);
Parameter Type Required
breadcrumb_or_title Breadcrumb or string true
routeName string
routeParameters array
routeAbsolute bool
position int
attributes array

Route

Assume that you have defined the following route :

/**
 * @Route("/var/{var}", name="my_route")
 */
/**
 * @Breadcrumb("Level 1")
 */
public function myAction()
{
    $this->get("apy_breadcrumb_trail")->add('Level 2', 'my_route', array("var" => "foo"));
    $this->get("apy_breadcrumb_trail")->add('Level 3');
}

Will render the following breadcrumb trail :

Level 1 > Level 2 > Level 3

Position

/**
 * @Breadcrumb("Level 1")
 */
public function myAction()
{
    $this->get("apy_breadcrumb_trail")->add('Level 2', null, array(), false, 1);
    $this->get("apy_breadcrumb_trail")->add('Level 3');
    $this->get("apy_breadcrumb_trail")->add('Level 4', null, array(), false, -1);
}

Will render the following breadcrumb trail :

Level 2 > Level 1 > Level 4 > Level 3

Note: position=0 will put the breacrumb to the end of the trail.

Reset the trail

/**
 * @Breadcrumb("Level 1")
 */
public function myAction()
{
    $this->get("apy_breadcrumb_trail")
        ->reset()
        ->add('Level 2')
        ->add('Level 3');
}

Will render the following breadcrumb trail :

Level 2 > Level 3