Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Kohana bootstrap - modal form

905 views

Published on

  • Be the first to comment

  • Be the first to like this

Kohana bootstrap - modal form

  1. 1. Julio Pari - CodigoAgil.com Bootstrap - Kohana Framework PHP - JQuery Julio Pari - CodigoAgil.com View_List: list.php View_Edit: edit.php <a data-toggle="modal-form" href="/backend/configuration/edit/<?php echo $rs_configuration->id; ?>" class="btn btn-info" data-target="#modal-form"> <i class="icon-edit icon-white"></i> </a> <form action="/backend/configuration/edit/<?php echo $rs_configuration->id ?>" class="form-horizontal" method="POST"> <div class="modal-header"> <button class="btn close" data-dismiss="modal">×</button> <h2><i class=""></i><span class="break"></span>Editar</h2> </div> <div class="modal-body"> <div class="control-group"> <label class="control-label">Clave:</label> <div class="controls"> <input name="key" id="key" type="text" value="<?php echo $rs_configuration->key; ?>" /> </div> </div> <div class="control-group"> <label class="control-label">Valor:</label> <div class="controls"> <input name="value" id="value" type="text" value="<?php echo $rs_configuration->value; ?>" /> </div> </div> </div> <div class="modal-footer"> <button class="btn" data-dismiss="modal">Cerrar</button> <input type="submit" value="Guardar" class="btn btn-primary" /> </div> </form>
  2. 2. Julio Pari - CodigoAgil.com Controller: configuration.php <?php defined('SYSPATH') or die('No direct script access.'); class Controller_Backend_Configuration extends Controller_Backend_Template { public function action_list() { $ls_configuration = ORM::factory('config_configuration')->find_all(); $view_configuration_list = View::factory('backend/configuration/list')->set("ls_configuration", $ls_configuration); $this->template->set('content', $view_configuration_list); } public function action_new(){ $this->action_edit(FALSE); } public function action_edit($edit = TRUE){ $this->auto_render = FALSE; $valid = Validation::factory($this->request->post()) ->rule('key', 'not_empty') ->rule('value', 'not_empty'); $id = $edit ? $this->request->param('id') : NULL; $rs_configuration = ORM::factory('config_configuration', $id); if ($this->request->method() == 'POST') { $rs_configuration->values($this->request->post()); if ($valid->check()) { $rs_configuration->save(); $this->request->redirect('backend/configuration/list'); } } $content = View::factory('backend/configuration/edit') ->set('rs_configuration', $rs_configuration); $this->response->body($content); } public function action_delete() { if(!$id = $this->request->param('id')){ $this->request->redirect('backend/configuration/list'); } $rs_configuration = ORM::factory('config_configuration', $id); //$rs_configuration->delete(); $this->request->redirect('backend/configuration/list'); } }
  3. 3. Julio Pari - CodigoAgil.com JS - JQuery $(document).ready(function() { /* ---------- Modal forms ---------- */ $('a[data-toggle=modal-form]').modalForm(); }); /* * ---------- Extending jQuery ---------- */ $.fn.extend({ modalForm: function () { $(this).click(function (e) { var $this = $(this); var $href = $this.attr('href'); var $target = $($this.data('target')); e.preventDefault(); $target.load($href, function (response, status, xhr) { if(status == 'error') { alert(xhr.responseText); } else { $target.modal('show') .on('shown', function () { $('body').css('overflow', 'hidden'); }) .on('hide', function () { $('body').css('overflow', 'visible'); }); } }); }) } });

×