Skip to content

Instantly share code, notes, and snippets.

View taleeb35's full-sized avatar

taleeb35

  • United Arab Emirates
View GitHub Profile
<?php
App::uses('AppController', 'Controller');
class CountriesController extends AppController {
public $helpers = array('Js');
public function select() {
$countries = $this->Country->find('list');
$states = array();
public function find() {
$this->Country->recursive = -1;
if ($this->request->is('ajax')) {
$this->autoRender = false;
$country_name = $this->request->data['Country']['name'];
$results = $this->Country->find('all', array(
'conditions' => array('Country.name LIKE ' => '%' . $country_name . '%')
));
foreach($results as $result) {
<?php
echo $this->Form->create('Country', array('action' => 'find'));
echo $this->Form->input('name',array('id' => 'Autocomplete'));
echo $this->Form->submit();
echo $this->Form->end();
?>
<script type="text/javascript">
$(document).ready(function($){
$('#Autocomplete').autocomplete({
source:'<?php=$this->Html->url(array("controller" => "countries","action"=> "find")); ?>',,
public function find() {
if ($this->request->is('ajax')) {
$this->autoRender = false;
$country_name = $this->request->data['Country']['name'];
$results = $this->Country->find('all', array(
'conditions' => array('Country.name LIKE ' => '%' . $country_name . '%'),
'recursive' => -1
));
<?php
echo $this->Form->create('Country', array('action' => 'find'));
echo $this->Form->input('name',array('id' => 'Autocomplete'));
echo $this->Form->submit();
echo $this->Form->end();
?>
<script type="text/javascript">
$(document).ready(function($){
$('#Autocomplete').autocomplete({
source:'<?= $this->Html->url(array("controller" => "countries","action"=> "find")); ?>',
@taleeb35
taleeb35 / AutoComplete.php
Last active August 20, 2017 09:50
Auto Complete Search in Cakephp
//Controller Action
public function find() {
if ($this->request->is('ajax')) {
$this->autoRender = false;
$country_name = $this->request->query('term');
$results = $this->Country->find('all', array(
'conditions' => array('Country.name LIKE ' => '%' . $country_name . '%')
@taleeb35
taleeb35 / ChainSelection.php
Created September 20, 2014 03:32
Chain Selection in Cakephp
<?php
App::uses('AppController', 'Controller');
class CountriesController extends AppController {
public $helpers = array('Js');
public $components = array('RequestHandler');
public function select() {
$countries = $this->Country->find('list');
@taleeb35
taleeb35 / Delete.php
Last active August 29, 2015 14:06
Delete with Jquery
public function delete($id = null) {
if($this->request->is('ajax')) {
//$this->autoRender = false;
if ($this->User->delete($id)) {
$response = $this->Session->setFlash(__('User deleted'));
$response .= $this->redirect(array('action' => 'index'));
} else {
$response = $this->Session->setFlash(__('User was not deleted'));
$response.= $this->redirect(array('action' => 'index'));
}
@taleeb35
taleeb35 / delete.js
Created September 20, 2014 16:24
Delete
$(document).ready(function() {
$('a.delete').click(function(e) {
var __this = this;
e.preventDefault();
var parent = $(this).parent("td").parent("tr");
$.ajax({
type: 'get',
url: $(__this).attr("href"),
beforeSend: function() {
parent.animate({'backgroundColor':'#fb6c6c'},300);
@taleeb35
taleeb35 / delete.php
Created September 20, 2014 16:25
Delete (Php)
public function delete($id = null) {
if($this->request->is('ajax')) {
//$this->layout = 'ajax';
$response = 'Fail';
if ($this->User->delete($id)) {
$response= 'OK';
}
$this->set('response', $response);
}
}