Articleshttp://bakery.cakephp.org/Latest Articlesen-usSphinx Search Behavior for Cake 2.0+http://bakery.cakephp.org/articles/nabeel/2012/02/21/sphinx_search_behavior_for_cake_2_0http://bakery.cakephp.org/articles/nabeel/2012/02/21/sphinx_search_behavior_for_cake_2_0https://github.com/nshahzad/Sphinx-CakePHPBehaviorsTue, 21 Feb 2012 17:27:22 +0000CakePHP Big Data Behaviorhttp://bakery.cakephp.org/articles/jarriett/2012/02/18/cakephp_big_data_behaviorhttp://bakery.cakephp.org/articles/jarriett/2012/02/18/cakephp_big_data_behavior<h2>Background</h2><hr/><p> My company uses CakePHP for most of our applications. However, we were running into efficiency issues when working with large amounts of data. It’s not uncommon for us to insert hundreds of thousands of rows with a single process. Additionally, we needed an efficient way to work with those hundreds of thousands of pieces of data.</p><p> So, after some investigation I narrowed our efficiency...</p>BehaviorsSat, 18 Feb 2012 05:05:24 +0000Formatos de fechashttp://bakery.cakephp.org/articles/rikkin/2012/01/26/formatos_de_fechashttp://bakery.cakephp.org/articles/rikkin/2012/01/26/formatos_de_fechas?php class DateformatBehavior extends ModelBehavior {//formato que queremos. var $dateFormat = 'd.m.Y';//formato de la base de datos. var $databaseFormat = 'Y-m-d';function setup {$this-model = $model;}function _changeDateFormat{return date);}function _changeDate{foreach{if){$queryDataConditions[$key] = $this-_changeDate;} else {$columns = $this-model-getColumnTypes;//sacamos las columnas que n...BehaviorsThu, 26 Jan 2012 22:10:45 +0000Dateformatterhttp://bakery.cakephp.org/articles/rikkin/2012/01/26/dateformatterhttp://bakery.cakephp.org/articles/rikkin/2012/01/26/dateformatter ?php class DateformatBehavior extends ModelBehavior {//Our formatvar $dateFormat = 'd.m.Y';//datebase Formatvar $databaseFormat = 'Y-m-d';function setup {$this-model = $model;}function _changeDateFormat{return date);}//This function search an array to get a date or datetime field. function _changeDate{foreach{if){$queryDataConditions[$key] = $this-_changeDate;} else {$columns = $this-model-get...BehaviorsThu, 26 Jan 2012 22:06:12 +0000HABTM Add & Delete Behavior for CakePHP 2.0http://bakery.cakephp.org/articles/iandeth/2012/01/11/habtm_add_delete_behavior_for_cakephp_2_0http://bakery.cakephp.org/articles/iandeth/2012/01/11/habtm_add_delete_behavior_for_cakephp_2_0<h4>Updated Version of ExtendAssociationsBehavior for CakePHP 2.0.x</h4><h5>Download</h3><ul><li>Model/Behavior/ExtendAssociations2Behavior.php</li></ul><h4>Patch|Diff</h4><pre>$ diff -u old new--- Vendor/Model/Behavior/ExtendAssociationsBehavior.php2012-01-10 23:31:14.000000000 +0900+++ Vendor/Model/Behavior/ExtendAssociations2Behavior.php2012-01-10 23:33:57.000000000 +0900@@ -1,5 +1,6 @@ &lt;?php -class ExtendAssociationsBehavior extends ModelB...</pre></h5>BehaviorsWed, 11 Jan 2012 00:41:35 +0000Autocache Behavior for automaticly caching model querieshttp://bakery.cakephp.org/articles/ndejong/2011/11/26/autocache_behavior_for_automaticly_caching_model_querieshttp://bakery.cakephp.org/articles/ndejong/2011/11/26/autocache_behavior_for_automaticly_caching_model_queries<b><p>Catch the easier to use CakephpAutocachePlugin from Github here:-https://github.com/ndejong/CakephpAutocachePlugin</p></b><br>You really just need two files, <i>Model/Behavior/AutocacheBehavior.php</i> and <i>Model/Datasource/DummySource.php</i><br><br><b>Q: How do I use it?</b><br> - copy/symlink into place Model/Behavior/AutocacheBehavior.php<br> - copy/symlink into place Model/Datasource/DummySource.php<br> - add the $dummy datasource to Confi...BehaviorsSat, 26 Nov 2011 10:33:41 +0000Sluggable Behavior for easy permalinkshttp://bakery.cakephp.org/articles/vduglued/2011/11/25/sluggable_behavior_for_easy_permalinkshttp://bakery.cakephp.org/articles/vduglued/2011/11/25/sluggable_behavior_for_easy_permalinks<ul><li>Specify a source field from which the slug should be generated </li><li>Specify a database field into which the slug should be stored </li><li>Automatically handle potential duplicates, adding numerical suffixes accordinglyKeep slugs constant even when source field changes </li><li>Slug may be manually overridden without problems by putting it into the data array being saved in Cake</li></ul><p>Download the source from Github, and vi...</p>BehaviorsFri, 25 Nov 2011 22:41:42 +0000EAV Behaviorhttp://bakery.cakephp.org/articles/abalonepaul/2011/10/11/eav_behaviorhttp://bakery.cakephp.org/articles/abalonepaul/2011/10/11/eav_behavior[b]Solution[/b]For the last few years I have been using the Entity-Attribute-Value Data Model to store "variable variable data" for my applications. This has proved to be very powerful at reducing the code base and complexity of applications by more than 70%. While implementing this data model requires some upfront coding and complexity, you are rewarded with a flexible application that is rela...BehaviorsTue, 11 Oct 2011 03:48:46 +0000SQL Server StoredProcedure Behaviourhttp://bakery.cakephp.org/articles/icc97/2011/09/25/sql_server_storedprocedure_behaviourhttp://bakery.cakephp.org/articles/icc97/2011/09/25/sql_server_storedprocedure_behaviour## BehaviourFirst you need the behaviour. Save this code in app/models/behaviours/stored_procedure.php: ?php class StoredProcedureBehavior extends ModelBehavior { /** * execute a stored proc. Call executeMssqlSp to not confuse with the cake execute * Taken initially from: http://planetcakephp.org/aggregator/items/4390-cakephp-calling-oracle-stored-procedures-and-functions * * @param object $Mod...BehaviorsSun, 25 Sep 2011 15:01:51 +0000Uploadable Behvaiorhttp://bakery.cakephp.org/articles/mdunham918/2011/09/15/uploadable_behvaiorhttp://bakery.cakephp.org/articles/mdunham918/2011/09/15/uploadable_behvaiorDownload the behavior here:https://github.com/mdunham/Uploadable-BehaviorThen in your model let use Recipe as an example:<?php/** * Recipe Model */class Recipe extends AppModel {/** * Define the behavior of this model * * @var array */public $actsAs = array;}Then make sure you turn on enctype = multipart/formdata in your view:<?phpecho $this->Form->create); echo $this->Form->input;echo $this->Form->input);echo $this->Form->end);?>And thats all it takes to start using it you can customize it to work on specific fields and specific file types. Happy baking.BehaviorsThu, 15 Sep 2011 05:23:14 +0000Key/Value storage table behavior built with cakephp-2.0.0 RC1http://bakery.cakephp.org/articles/mdunham918/2011/09/14/key_value_storage_table_behavior_built_with_cakephp-2_0_0_rc1http://bakery.cakephp.org/articles/mdunham918/2011/09/14/key_value_storage_table_behavior_built_with_cakephp-2_0_0_rc1Download this behavior here:https://github.com/mdunham/KeyValue-Behavior--------------------------------I had a table called measurements and it contains five fields:+ id+ user_id+ key+ value+ createdI wanted to store a flexible amount of data, and I wanted to do it easily. So I created this KeyValue behavior which allows me to build the form this is what my add.ctp looks like:?phpecho $this-Fo...BehaviorsWed, 14 Sep 2011 21:19:33 +0000Automatic Validation Message For Core Validation Ruleshttp://bakery.cakephp.org/articles/rayhan/2011/06/24/automatic_validation_message_for_core_validation_ruleshttp://bakery.cakephp.org/articles/rayhan/2011/06/24/automatic_validation_message_for_core_validation_rules<p>Behavior: validation_message.php</p><code>?php/** * ValidationMessage behavior class. * * Display automatic validation message for core validation rules * * PHP versions 5 * * * Licensed under The MIT License * Redistributions of files must retain the above copyright notice. * * @author Md. Rayhan Chowdhury <ray@raynux.com> * @copyright Copyright 2010, Raynux.com. * @package cake * @subpackage cake.app.model.behaviors *...</ray></code>BehaviorsFri, 24 Jun 2011 06:10:00 +0000Multiple Validation Ruleshttp://bakery.cakephp.org/articles/Styles/2011/05/18/multiple_validation_ruleshttp://bakery.cakephp.org/articles/Styles/2011/05/18/multiple_validation_rules[php]class CheckValidationRulesBehavior extends ModelBehavior { function setup { // We do this in setup so the form reflects the changes // of the model's custom validation $varName = 'validate' . Inflector::camelize); if) { $model-validate = $model-{$varName}; } }}[/php]This is a very simple behavior to do this.Basically it checks your action name, and if a variable is set with rules for that ...BehaviorsWed, 18 May 2011 20:16:57 +0000FindBatch Behaviorhttp://bakery.cakephp.org/articles/2011/03/12/findbatch_behaviorhttp://bakery.cakephp.org/articles/2011/03/12/findbatch_behavior# Codehttps://github.com/jamiemill/cakephp_find_batch# What is it?It's a plugin behavior that provides a way of finding all records in batches rather than all at once, so that you can loop through huge lists of records without running out of memory.Rather than returning any results, it calls a callback function you provide and passes the current batch of results to it, along with a $batchInfo a...BehaviorsSat, 12 Mar 2011 09:36:33 +0000Behavior for Model Inheritance: the missing featurehttp://bakery.cakephp.org/articles/santino83/2011/02/19/behavior_for_model_inheritance_the_missing_featurehttp://bakery.cakephp.org/articles/santino83/2011/02/19/behavior_for_model_inheritance_the_missing_featureThis is a simple behavior who add the flexibility to implement STI , MTI and SMTI, a mix between STI and MTI.[b]Single Table Inheritance[/b]This kind of inheritance holds the parent's fields and the child's fields in the same database table, using a field to distinguish between children. See for example [url]http://www.martinfowler.com/eaaCatalog/singleTableInheritance.html[/url]Implementing th...BehaviorsSat, 19 Feb 2011 18:45:35 +0000Transaction behaviorhttp://bakery.cakephp.org/articles/Jippi/2007/01/29/transaction_behaviorhttp://bakery.cakephp.org/articles/Jippi/2007/01/29/transaction_behavior[h4]Example use[/h4]Sample model - note the $actsAsTo change default settings do:[code]var $actsAs = array;[/code][model]class Order extends AppModel{ var $name = 'Order'; var $actsAs = array; var $hasMany = array;[/model][controller]class OrderController extends AppController { var $name = 'Order'; var $uses = array; function checkout { if) { $this-Order-begin; // Start our transaction if ) { ...BehaviorsMon, 29 Jan 2007 14:19:00 +0000Rangeable Behavior: Find ranged based on a lat/lon fieldhttp://bakery.cakephp.org/articles/zeroasterisk/2010/12/10/rangeable_behavior_find_ranged_based_on_a_lat_lon_fieldhttp://bakery.cakephp.org/articles/zeroasterisk/2010/12/10/rangeable_behavior_find_ranged_based_on_a_lat_lon_fieldFor code, better notes, and updates: https://github.com/zeroasterisk/cakephp-behavior-rangeableh1. Rangeable Behavior for CakePHPAfter some really shoddy implementations of this functionality as components and whatnot, I finally made a clean and simple behavior which you can use naturally as a custom find type, even within paginate.It will also sort the results for you based on distance to the ...BehaviorsFri, 10 Dec 2010 10:20:37 +0000DBO extension to get keyed resultshttp://bakery.cakephp.org/articles/mbates/2010/11/29/dbo_extension_to_get_keyed_results_1http://bakery.cakephp.org/articles/mbates/2010/11/29/dbo_extension_to_get_keyed_results_1[b]App Model[/b]I have been using Matt Currys excellent custom find to create my own 'cake like' finds e.g.$this-Model-find;So I used Matts custom finds to create a new find in my app_model.php. The code here is a modified version of the core Model::find method[code]/** * Duplicate of find but return results in a keyed array * * @param array $query options array * @return array $results */funct...BehaviorsMon, 29 Nov 2010 13:28:30 +0000CustomFinds Behaviorhttp://bakery.cakephp.org/articles/Danielpk/2010/09/25/customfinds-behaviorhttp://bakery.cakephp.org/articles/Danielpk/2010/09/25/customfinds-behavior[p]Behavior that enables you to config custom finds at Model in order to use with Model-find;[/p][h3]Installation[/h3]- You can download from Github: [url]http://github.com/mobvox/CustomFinds[/url][model]class Product extends AppModel{ //... var $actsAs = array; var $customFinds = array, 'contain' = array, 'conditions' = array, 'recursive' = 1, //All others find options ) ); //...}[/model][cont...BehaviorsSat, 25 Sep 2010 13:15:54 +0000File Model behaviorhttp://bakery.cakephp.org/articles/thedilab/2010/08/25/file-model-behaviorhttp://bakery.cakephp.org/articles/thedilab/2010/08/25/file-model-behavior[h4]How to use this behavior:[/h4]Download this behavior and place it inside folder "app/modes/behaviors/file_model.php":[model]/* * Developed by The-Di-Lab * www.the-di-lab.com * www.startutorial.com * contact at thedilab@gmail.com * FileMode v2.0 support multiple fields */App::import);class FileModelBehavior extends ModelBehavior { /** * Model-specific settings * @var array */ public $setting...BehaviorsWed, 25 Aug 2010 00:28:21 +0000