Created
November 2, 2011 14:23
-
-
Save junichi11/1333758 to your computer and use it in GitHub Desktop.
BootstrapFormHelper for CakePHP2.0
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* CakePHP BootstrapFormHelper | |
* CakePHP version 2.0+ | |
* Usage: | |
* // In Your Controller | |
* public $helpers = array('Form' => array('className' => 'BootstrapForm')); | |
* // In Your View | |
* $this->Form->input('name', array('label' => 'Name')); | |
* @author junichi11 | |
*/ | |
App::uses('FormHelper', 'View/Helper'); | |
class BootstrapFormHelper extends FormHelper { | |
public $helpers = array('Form', 'Html'); | |
public function __construct(View $View, $settings = array()) { | |
parent::__construct($View, $settings); | |
} | |
public function input($fieldName, $options = array()) { | |
$output = ''; | |
if(isset($options['label']) && $options['label'] != false){ | |
$output = $this->Html->tag('label', $options['label']); | |
$options['label'] = false; | |
} | |
$output .= parent::input($fieldName, $options); | |
$error = ''; | |
if($this->Form->error($fieldName)){ | |
$error = ' error'; | |
} | |
$output = $this->Html->tag('div', $output, array('class' => 'clearfix'. $error)); | |
return $output; | |
} | |
public function submit($caption = null, $options = array()) { | |
$default = array( | |
'class' => 'btn primary', | |
); | |
$options = array_merge($default, $options); | |
return $this->Html->tag('div', parent::submit($caption, $options), array('class' => 'actions')); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* CakePHP BootstrapSessionHelper | |
* Usage: | |
* // In Your Controller | |
* public $helpers = array('Session' => array('className' => 'BootstrapSession')); | |
* // In Your View | |
* $this->Session->flash(); | |
* // create element | |
* flash.ctp | |
* @author junichi11 | |
*/ | |
App::uses('SessionHelper', 'View/Helper'); | |
class BootstrapSessionHelper extends SessionHelper { | |
public $helpers = array('Session'); | |
public function __construct(View $View, $settings = array()) { | |
parent::__construct($View, $settings); | |
} | |
public function flash($key = 'flash', $attrs = array()) { | |
$default = array( | |
'element' => 'flash', | |
); | |
$attrs = array_merge($default, $attrs); | |
return parent::flash($key, $attrs); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="alert-message warning" data-alert="close"> | |
<a class="close" href="#">×</a> | |
<?php echo $message;?> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment