Skip to main content

Posts

Save multiple rows record in cakephp

You can also use this format to save several records and their HABTM associations with  saveAll() , using an array like the following: Array ( [0] => Array ( [Note] => Array ( [id] => 0 [company_id] => 53218f2c-91f8-4168-a1d6-09b50a28b132 [cid] => 53199bf6-2e78-43c2-8a08-084f0a28b132 [author] => vh admin [notedate] => 2014-09-05 [time] => 16:08:46 [type] => client [type_id] => 53199bf6-2e78-43c2-8a08-084f0a28b132 [subject] => Inactivated [reason] => Feedback issues [message] => Views are the presentation layer in CakePHP. They convert the data fetched from Models into the output format requested by the client. Read more about ) ) [1] => Array ...

Softdelete behaviors in cakephp

<?php class SoftDeleteBehavior extends ModelBehavior { /**  * Default settings  *  * @var array $default  */ public $default = array('deleted' => 'deleted_date'); /**  * Holds activity flags for models  *  * @var array $runtime  */ public $runtime = array(); /**  * Setup callback  *  * @param object $model  * @param array $settings  */     public function setup(&$model, $settings = array()) {         if (empty($settings)) {             $settings = $this->default;         } elseif (!is_array($settings)) {             $settings = array($settings);         }         $error = 'SoftDeleteBehavior::setup(): model ' . $model->alias . ' has no field ';         $fields = $this->_normalizeFields($model, $settings)...

jQuery Autocomplete

<link rel="stylesheet" type="text/css" href="/css/jquery.autocomplete.css" /> <script src="js/jquery/jquery-1.7.1.min.js"></script> <script src="js/jquery/jquery.ui.autocomplete.min.js"></script> jQuery autocomplete with jSON <script>var data = [ {"label" : "Aragorn"}, {"label" : "Arwen"}, {"label" : "Bilbo Baggins"}, {"label" : "Boromir"}, {"label" : "Frodo Baggins"}, {"label" : "Gandalf"}, {"label" : "Gimli"}, {"label" : "Gollum"}, {"label" : "Legolas"}, {"label" : "Meriadoc Merry Brandybuck"}, {"label" : "Peregrin Pippin Took"}, {"label" : "Samwise Gamgee"} ]; </script> <script> $(function() { $( ...

Cakephp Model Attributes

useDbConfig: The useDbConfig property is a string that specifies the name of the database connection to use to bind your model class to the related database table. Example usage: class Example extends AppModel {     public $useDbConfig = 'alternate'; } useTable: The useTable property specifies the database table name. class Example extends AppModel {     public $useTable = false; // This model does not use a database table } Alternatively: class Example extends AppModel {     public $useTable = 'exmp'; // This model uses a database table 'exmp' } Order The default ordering of data for any find operation. Possible values include: $order = "field" $order = "Model.field"; $order = "Model.field asc"; $order = "Model.field ASC"; $order = "Model.field DESC"; $order = array("Model.field" => "asc", "Model.field2" => "DESC"); virtualFields Array of virtual fields this model h...

Pagination with MySql, jQuery & Php

Ajax pagination with MySQL, PHP and jQuery Method 1: Javascript : <script type="text/javascript"> $(document).ready(function(){ function loading_show(){ $('#loading').html("<img src='images/loading.gif'/>").fadeIn('fast'); } function loading_hide(){ $('#loading').fadeOut('fast'); }                 function loadData(page){ loading_show();                     $.ajax ({ type: "POST", url: "load_data.php", data: "page="+page, success: function(msg) { $("#container").ajaxComplete(function(event, request, settings) { loading_hide(); $("#container").html(msg); }); } }); } loadData(1);  $('#container .pagination li.active').on('click',function(){ var page = $(this).attr('p'); loadData(page); }); }); </script> ...

Export CSV in cakephp

1. Download XLS sheet in CakePHP In the controller function function downloadXLS(){         $this->set('contacttracker', $this->paginate()); $this->layout = false; header ("Expires: Mon, 28 Oct 2008 05:00:00 GMT"); header ("Last-Modified: " . gmdate("D,d M YH:i:s") . " GMT"); header ("Cache-Control: no-cache, must-revalidate"); header ("Pragma: no-cache"); header ("Content-type: application/vnd.ms-excel"); header ("Content-Disposition: attachment; filename=contacts_".date('d-m-Y').".xls"); header ("Content-Description: Generated Report" ); } In the view section download_xls.ctp <STYLE type="text/css"> .table{font-family:arial; font-size:12px;} .tdheading{font-weight:bold;color:#fff;background-color:#2E2E2E;border-width: 0.5pt;border: solid;border-color:#fff; } .tdcontent{border-width:0.5pt; border: solid;} ...

Cakephp Html Helper

Meta Tag <? php   echo   $this -> Html -> charset ();   ?> Will output: < meta   http - equiv = "Content-Type"   content = "text/html; charset=utf-8"   /> Link Tag <? php   echo   $this -> Html -> link (      'Delete' ,      array ( 'controller'   =>   'recipes' ,  'action'   =>   'delete' ,  6 ),      array (),      "Are you sure you wish to delete this recipe?" ); ?> Will output: < a   href = "/recipes/delete/6"   onclick = "return confirm('Are you sure you wish to delete this recipe?');" > Delete </ a > Creating Table header <?php   echo   $this -> Html -> tableHeaders (      array ( 'Date' , 'Title' , 'Active' ),      array ( 'class'   =>   'status' ),   ...