From 8fa844754bb91f00031230ab454a7f960fb12a6f Mon Sep 17 00:00:00 2001 From: Chinmay Date: Wed, 15 Jul 2015 14:39:35 +0530 Subject: [PATCH] CakePHP URL Filter --- Controller/MapsController.php | 53 +++++++++++++++++++++++++++++++++++ View/Maps/index.ctp | 8 ++++++ 2 files changed, 61 insertions(+) create mode 100644 Controller/MapsController.php create mode 100644 View/Maps/index.ctp diff --git a/Controller/MapsController.php b/Controller/MapsController.php new file mode 100644 index 0000000..1d2a973 --- /dev/null +++ b/Controller/MapsController.php @@ -0,0 +1,53 @@ +Auth->allow('view_map'); + $this->layout = 'map'; + } + public function view_map() { + $url=""; + if($this->params->named) + { + foreach ($this->params->named as $key=>$value) { + if($value!=$value['0']) + $url .=$value."-"; + } + } + else { + $url ="All New and Used Car"; + } + $condition = array(); + if (($this->request->is('post') || $this->request->is('put')) && isset($this->data['Map'])) { + $filter_url['page'] = 1; + foreach ($this->data['Map'] as $name => $value) { + if ($value) { + $filter_url[$name] = urlencode($value); + } + } + return $this->redirect($filter_url); + }else{ + if ($this->params['named']['street_name']) { + $condition[] = array('User.address' => $this->params['named']['street_name']); + } + if ($this->params['named']['zip']) { + $condition[] = array('User.zip' => $this->params['named']['zip']); + } + } + if($condition){ + $this->set('carcount', $this->User->find('all',array('conditions' => $condition))); + }else{ + $this->set('carcount', $this->User->find('all')); + } + } +} + + +?> \ No newline at end of file diff --git a/View/Maps/index.ctp b/View/Maps/index.ctp new file mode 100644 index 0000000..b588a3d --- /dev/null +++ b/View/Maps/index.ctp @@ -0,0 +1,8 @@ + 'maps', 'action' => 'view_map'); + echo $this->Form->create('Map',array('url'=>$base_url)); + echo $this->Form->input('street_name',array('div'=>FALSE, 'type'=>'text','id'=>'street_name','label'=>false,'placeholder'=>"Street Name")); + echo $this->Form->input('zip',array('div'=>FALSE, 'type'=>'text','id'=>'zip','label'=>false,'placeholder'=>"Zip Code")); + echo $this->Form->input('Get Location',array('div'=>FALSE, 'type'=>'submit', 'id'=>'submit','label'=>false)); + echo $this->Form->end(); +?> \ No newline at end of file