Search code examples
cakephptwitter-bootstrapblockcakephp-2.2

CakePHP 2: Passing Buttons in an element depending on view


Id like to pass buttons from the cakePHP 2 (note: I'm using Twitter Bootstrap 2.2.1) into an Element in app/View/Elements/Toolbar.ctp

<div class="actions">
<?php echo $this->Html->link(__('New User'), array('action' => 'add'), array('class' => 'btn btn-small',)); ?>
</div>

Above is an example of the button. Depending on the view, I'd like to pass in different Buttons with different actions. How do I do that? With Elements, Blocks, requestaction() or what?


Solution

  • The cakephp way doing would look like this

    In view

    <?= $this->element('toolbar', array('button' => $button_type)) ?>
    

    in element there will be variable called $button available. Note that $button_type variable is also available in element.

    That should do it