Last active
December 14, 2015 19:09
-
-
Save rederlo/023209ddeed967f2a33e to your computer and use it in GitHub Desktop.
Exemplo de Helper. Campo input+request
This file contains 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 | |
App::import('Helper', 'AppHelper'); | |
/** | |
* Created by PhpStorm. | |
* User: Ederlo Rodrigo de Oliveira | |
* Date: 14/12/15 | |
* Time: 13:52 | |
*/ | |
class CepHelper extends AppHelper | |
{ | |
/** | |
* @var array | |
*/ | |
public $helpers = array('Html', 'Form'); | |
/** | |
* @var array | |
*/ | |
public $compoments = array('LocateMe'); | |
public function input($name, $data = array(), $others = array()) | |
{ | |
$class = ['class' => 'cep']; | |
$input = $this->Form->input($name, array_merge($class, $data), $others) | |
. '<script>' | |
.'$(document).ready(function(){ | |
window.JSON_CEP = ""; | |
$(".'.$class['class'].'").on("change", function(){ | |
$.post("'.$this->Html->url('/',true).'user/users/api_locate.json",{cep : $(".'.$class['class'].'").val()} ,function(data){ | |
window.JSON_CEP = data; | |
console.log(data); | |
}); | |
}); | |
});' | |
. '</script>'; | |
return ($input); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Exemplo de Helper compatível com cake 2.x
para usar:
echo $this->Cep->input('nome');