Articleshttp://bakery.cakephp.org/Latest Articlesen-usForce saving with know primary keyhttp://bakery.cakephp.org/articles/2012/03/26/force_saving_with_know_primary_keyhttp://bakery.cakephp.org/articles/2012/03/26/force_saving_with_know_primary_keyAt first time insert in the app_model this function:<br /><br/><code>public function beforeSave{ parent::beforeSave; if && !is_null) { if) { $this-data[$this-alias][$this-primaryKey] = $opt['id'];} } return true;}</code><br/><br/>so, when you make a save in your code use this:<br/><br/><code>$this-save, array)</code><br/><br/>replace $fields with the fields array but NOT INSERT IN IT THE PRIMARY KEY FIELD.replace $newId with the know value of the primary key.u...ModelsMon, 26 Mar 2012 09:58:18 +0000Make salesforce objects more cake likehttp://bakery.cakephp.org/articles/mbates/2010/11/30/make_salesforce_objects_more_cake_likehttp://bakery.cakephp.org/articles/mbates/2010/11/30/make_salesforce_objects_more_cake_likeThere are 2 methods that you can add to app_model[code] // convert the object into an nested associative arrayfunction __getRecordData{$recordArray = array );if ){$recordArray[ $recordObject-type ][ 'id' ] = $recordObject-Id;}foreach{if ){$subRecord = $this-__getRecordData;foreach{// Add to array of sub recordsif ){// Checks to see if this is already an associatie arrayif ){$first = $recordArra...ModelsTue, 30 Nov 2010 13:17:27 +0000Google Weather API Datasourcehttp://bakery.cakephp.org/articles/anachronist/2010/11/28/google_weather_api_datasourcehttp://bakery.cakephp.org/articles/anachronist/2010/11/28/google_weather_api_datasourceconditions in the model for the datasource:['condition']['zip'] = Zip Code['condition']['country'] = Country[php]?phpclass WeatherSource extends DataSource {public function read) {$dom = new DOMDocument;$dom-loadXML));if { echo 'Error while parsing the document'; exit;}$s = simplexml_import_dom;//aktuelles wetter$return[0]['condition'] = strtolower$s-weather-current_conditions-condition['data']...ModelsSun, 28 Nov 2010 04:21:02 +0000GeoIP Data Source Collection - Maxmind, WIPmania, Ipinfodb - many geoip providers for you to choose from!http://bakery.cakephp.org/articles/dereklio/2010/09/07/geoip-data-source-collection-maxmind-wipmania-ipinfodb-many-geoip-providers-for-you-to-choose-fromhttp://bakery.cakephp.org/articles/dereklio/2010/09/07/geoip-data-source-collection-maxmind-wipmania-ipinfodb-many-geoip-providers-for-you-to-choose-from[h2]Design Consideration[/h2][list][li]It has to be a drop-in solution - everything will be packaged into a plugin, and the developer only needs to drop in the plugin codes into their cakephp plugin folder and everything should works![/li][li]Geoip database provider will be configured in the database.php file just like all other database connection setting[/li][li]All geoip lookup codes are don...ModelsTue, 07 Sep 2010 04:00:21 +0000Twitter model plus plus (for the Twitter DataSource)http://bakery.cakephp.org/articles/rynop/2010/08/29/twitter-model-plus-plus-for-the-twitter-datasourcehttp://bakery.cakephp.org/articles/rynop/2010/08/29/twitter-model-plus-plus-for-the-twitter-datasourceThe CakePHP.org Cookbook has a great little example for a Twitter DataSource: [url]http://book.cakephp.org/view/1077/An-Example[/url]I've expanded on the model in the example to add a few helpful methods. Figured I would share it with the world as shrinking URL's for twitter is pretty commonplace today. Once you are familiar with the CookBook example my model is really easy to use.[h3]The code ...ModelsSun, 29 Aug 2010 02:40:52 +0000UPS & FedEx DataSourcehttp://bakery.cakephp.org/articles/kylerobinsonyoung/2010/08/23/ups-fedex-datasourcehttp://bakery.cakephp.org/articles/kylerobinsonyoung/2010/08/23/ups-fedex-datasource[p]Looking to get estimated shipping rates from UPS and/or FedEx? Try these datasources.[/p][p]These are part of a shipping resources packages I am building.[/p][p]Available on github: [url]http://github.com/shama/CakePHP-Shipping[/url][/p][h3]UPS Model Example[/h3][h4]app/models/ups.php[/h4][model]/** * UPS Model * Example usage of the UPS datasource. * * Must have /app/config/database.php set...ModelsMon, 23 Aug 2010 09:08:27 +0000Optimizing Model loading with LazyModelhttp://bakery.cakephp.org/articles/Frank/2010/08/10/optimizing-model-loading-with-lazymodelhttp://bakery.cakephp.org/articles/Frank/2010/08/10/optimizing-model-loading-with-lazymodel[h3]Background[/h3]To be honest, this wasn’t my idea at all. At first the idea showed up as a bin by José Lorenzo Rodríguez . Then Matt Curry picked it up and improved it . Next José Lorenzo Rodríguez forked it and improved it even more . I think that got a bit out of hand there and that is why I started a new project that uses a slightly different approach.[h3]Features[/h3][ulist][li]Ful...ModelsTue, 10 Aug 2010 15:22:00 +0000Habtm Validatable Behaviorhttp://bakery.cakephp.org/articles/nachopitt/2010/07/01/habtm-validatable-behaviorhttp://bakery.cakephp.org/articles/nachopitt/2010/07/01/habtm-validatable-behaviorThis behavior gives models the ability to validate the save or update of a HABTM associated model . First I will show how to use it, and then I will show the code.Example:Post HABTM TagUsage:post.php[model]var $validate = array)));var $actsAs = array; //This will apply to all HABTM related modelsvar $actsAs = array; //One fieldvar $actsAs = array); //One or multiple fields[/model]posts_controll...ModelsThu, 01 Jul 2010 11:50:46 +0000Twilio Datasourcehttp://bakery.cakephp.org/articles/aaroninfidel/2010/06/07/twilio-datasourcehttp://bakery.cakephp.org/articles/aaroninfidel/2010/06/07/twilio-datasource<p>Here is a simple example of how to use Datasources and <code>HttpSocket</code> to implement a very basic Twilio source that allows querying the Twilio API as well as posting new text messages to a configured account.</p><p class="note"><strong>This example will only work in PHP 5.2 and above</strong>, due to the use of <code>json_decode</code> for the parsing of JSON formatted data.</p><p>You would place the Twilio datasource in <kbd>app/models/datasources/twilio_sour...</kbd></p>ModelsMon, 07 Jun 2010 02:36:56 +0000Microsoft Windows Azure Tables Datasourcehttp://bakery.cakephp.org/articles/Howard/2010/02/02/microsoft-windows-azure-tables-datasourcehttp://bakery.cakephp.org/articles/Howard/2010/02/02/microsoft-windows-azure-tables-datasourceThis is a DataSource file for CakePHP to utilize Microsoft's Windows Azure Tables system. With the Azure Tables you can store terabytes of data providing excellent scalability with virtually no cap. The only limitation of Azure Tables is that because of how they are designed they are not relational, however Tables are [b]NOT[/b] limited to a specific set of fields. Two different entity sets wit...ModelsTue, 02 Feb 2010 08:45:22 +0000Example Datasource for Salesforce Enterprise http://bakery.cakephp.org/articles/cwestonr/2010/01/26/example-datasource-for-salesforce-enterprise-1http://bakery.cakephp.org/articles/cwestonr/2010/01/26/example-datasource-for-salesforce-enterprise-1I have built a sample way to integrate the Salesforce API with CakePHP.The zip package is at [url]http://www.contangoadvisors.com/work/SalesforceCakePHPdatasource.zip[/url]This Datasource is for a Salesforce Enterprise implementationto use the other types you will have to modify the code.This Package requires you to have the Salesforce PHP Toolkit 13.0 or greater.I wrote this as a simple implem...ModelsTue, 26 Jan 2010 08:27:23 +0000Simple way to memcache (almost) all database querieshttp://bakery.cakephp.org/articles/Molot/2010/01/08/simple-way-to-memcache-almost-all-database-querieshttp://bakery.cakephp.org/articles/Molot/2010/01/08/simple-way-to-memcache-almost-all-database-queriesText from now on assumes you have Memcached configured as default caching engine.The goal was to create simple and fast yet safe and universal caching for my models. Caching collections takes long time. Of course it allows to make much less calls to a model, but is that what we really want?What my code does not do is saving memory. If you often ask your database about crossing sets of data, don...ModelsFri, 08 Jan 2010 09:29:26 +0000Ticket Model for CakePHPhttp://bakery.cakephp.org/articles/Firecreek/2010/01/05/ticket-model-for-cakephphttp://bakery.cakephp.org/articles/Firecreek/2010/01/05/ticket-model-for-cakephp[h3]Overview[/h3]Use this model to create tickets or tokens so you can match a url link in an email to reset a users password, activate an account, moderate content or anything else you can think of.I saw there were a few alternatives but using components. This is a cleaned up and more basic version. Thanks to mndeaves for a starting block :) You're welcome to alter the code to your needs. You ...ModelsTue, 05 Jan 2010 14:44:00 +0000LDAP data source with full CRUD supporthttp://bakery.cakephp.org/articles/analogrithems/2009/11/08/ldap-data-source-with-full-crud-supporthttp://bakery.cakephp.org/articles/analogrithems/2009/11/08/ldap-data-source-with-full-crud-supportBefore we get started I want to state the environment I was using to do my work was Redhat Enterprise 5.2 & Fedora 10 with redhat directory server 8.1 and Fedora directory server 1.2. Now while LDAP is a standard protocol, some of the driver may have become centric to those platforms, so if this is the case, please leave me a comment and I will try to correct the ldap data source I'm working on...ModelsSun, 08 Nov 2009 19:29:12 +0000CSV Reader Modelhttp://bakery.cakephp.org/articles/CakePOWER/2009/09/25/csv-reader-modelhttp://bakery.cakephp.org/articles/CakePOWER/2009/09/25/csv-reader-modelI know there are DataSource to access different types of data but i need a way to define what file to read "on the fly" with an absolute path.First let me say how to use this Model:[code]?phpclass FooController extends AppController {var $uses = array;function read_csv {$this-Csv-setFile;$list = $this-Csv-find);}}?[/code]You can use some find type such "first", "all", "count".Csv model can defi...ModelsFri, 25 Sep 2009 09:03:59 +0000Get Twitter RSS Feeds with CakePHPhttp://bakery.cakephp.org/articles/Firecreek/2009/07/08/get-twitter-rss-feeds-with-cakephphttp://bakery.cakephp.org/articles/Firecreek/2009/07/08/get-twitter-rss-feeds-with-cakephp[h3]Installation[/h3][list][li]Save this script below into your models directory[/li][li]Change your Twitter ID and Twitter Name[/li][li]Add to your $uses controller variable, public $uses = array[/li][li]Add to your controller method, $this-set);[/li][li]Then add to your view[/li][/list][model] /** * Get Twitter Updates * * $twits = $this-Twitter-find); * * @author Darren Moore, zeeneo@gmail.c...ModelsWed, 08 Jul 2009 14:45:01 +0000FMCakeMix: A Full Read/Write Datasource for FileMakerhttp://bakery.cakephp.org/articles/alexg/2009/06/12/fmcakemix-a-full-read-write-datasource-for-filemakerhttp://bakery.cakephp.org/articles/alexg/2009/06/12/fmcakemix-a-full-read-write-datasource-for-filemaker[h3]Installation[/h3][h4]FX.php[/h4][p]FX.php is a PHP class created by Chris Hansen to speak with FileMaker via XML. The FMCakeMix driver uses fx.php to send queries to FileMaker and is necessary for the driver’s functionality. Install FX.php by downloading the files from http://www.iviking.org/FX.php/ and placing the FX.php, FX_Error.php, FX_Constants.php, and image_proxy.php files at the r...ModelsFri, 12 Jun 2009 12:58:09 +0000Vimeo Datasourcehttp://bakery.cakephp.org/articles/pointlessjon/2009/05/08/vimeo-datasourcehttp://bakery.cakephp.org/articles/pointlessjon/2009/05/08/vimeo-datasource[sub]Note that this particular datasource leverages the Vimeo Simple API as well as the Vimeo oEmbed API. A datasource utilizing the Vimeo Advanced API is on the way. See [url]http://vimeo.com/api[/url] for details.[/sub][h3]Installation[/h3][ulist][li]Place vimeo_source.php in your app/models/datasources folder[/li][li]Add the following declarative in your database.php file[/li][/ulist][code]?...ModelsFri, 08 May 2009 14:33:00 +0000Geocode location with CakePHPhttp://bakery.cakephp.org/articles/Firecreek/2009/01/24/geocode-location-with-cakephphttp://bakery.cakephp.org/articles/Firecreek/2009/01/24/geocode-location-with-cakephp[h3]Overview[/h3]Cake model to call map API providers to get lng/lat and sometimes more address information depending on the provider.[h3]Example[/h3][url]http://www.zeen.co.uk/code/view/geocode-location-with-cakephp[/url][h3]Map API Providers[/h3][ulist][li]Google Map API [url]http://code.google.com/apis/maps/[/url][/li][li]Multimap Open API [url]http://www.multimap.com/openapi/[/url][/li][li]...ModelsSat, 24 Jan 2009 10:12:56 +0000A CakePHP ADODB data source driver for MS Accesshttp://bakery.cakephp.org/articles/aspeakman/2008/12/29/a-cakephp-adodb-data-source-driver-for-ms-accesshttp://bakery.cakephp.org/articles/aspeakman/2008/12/29/a-cakephp-adodb-data-source-driver-for-ms-access[h2]Database Configuration[/h2][code]?phpvar $default = array};Dbq=C:\DOCUMENTS AND SETTINGS\User\My Documents\Test.mdb;','login' = 'Admin','password' = '','database' = 'default','prefix' = 'tbl');?[/code][h2]Code[/h2]Here is the code which goes in app/models/datasources/dbo/dbo_adodb_access.php[code]?php/** * Include AdoDB files. */App::import);/** * Included cake libraries */uses ;/** * MS Ac...ModelsMon, 29 Dec 2008 17:31:20 +0000