Skip to content

Instantly share code, notes, and snippets.

@rederlo
Last active December 14, 2015 19:09
Show Gist options
  • Save rederlo/023209ddeed967f2a33e to your computer and use it in GitHub Desktop.
Save rederlo/023209ddeed967f2a33e to your computer and use it in GitHub Desktop.
Exemplo de Helper. Campo input+request
<?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);
}
}
@rederlo
Copy link
Author

rederlo commented Dec 14, 2015

Exemplo de Helper compatível com cake 2.x

para usar:

echo $this->Cep->input('nome');

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment