Articleshttp://bakery.cakephp.org/Latest Articlesen-usPrevent render layout elements with the render of some views!http://bakery.cakephp.org/articles/saidbakr/2012/04/20/prevent_render_layout_elements_with_the_render_of_some_viewshttp://bakery.cakephp.org/articles/saidbakr/2012/04/20/prevent_render_layout_elements_with_the_render_of_some_viewsConsider the following example, there is an element that displays the top searched keywords and it is named top_searches.ctp. This element is placed in the layout to be rendered under the search box element.Suppose now, we have an index view that lists all searched keywords and we don't want to make the top_searches elements to be rendered while we call the index view.We should add the followin...SnippetsFri, 20 Apr 2012 00:07:03 +0000Auth – inline authorization the easy wayhttp://bakery.cakephp.org/articles/euromark/2012/04/07/auth_–_inline_authorization_the_easy_wayhttp://bakery.cakephp.org/articles/euromark/2012/04/07/auth_–_inline_authorization_the_easy_way### Status quoWe would need to check the session manually against the roles we want to grant access to. This can get pretty hairy with more than one role allowed .### PreparationsWe first need to make the class usable by putting this in our `/Config/bootstrap.php`:// these IDs match the role_ids in the DBdefine;define;define;define;// enable the Auth classApp::uses;I like to use constants as th...SnippetsSat, 07 Apr 2012 12:35:42 +0000HTML 5 Multiple File Upload With Cakehttp://bakery.cakephp.org/articles/veganista/2012/01/31/html_5_multiple_file_upload_with_cakehttp://bakery.cakephp.org/articles/veganista/2012/01/31/html_5_multiple_file_upload_with_cakeWith HTML5 comes the ability to select multiple files using a regular file input field.It took me a little while to work out how to do this so I thought I'd post it here.To start with we are trying to get html similar to this using the cake input helper. <input name='uploads[]' type=file multiple>To achieve this we need to use the Form helper as so: ?php echo $this-Form-create); echo $this-Form-input); echo $this-Form-end; ?From the con...SnippetsTue, 31 Jan 2012 19:58:38 +0000960 Fluid Grid System Bake Templates CakePHP 2.1http://bakery.cakephp.org/articles/Petert/2012/01/30/960_fluid_grid_system_bake_templates_cakephp_2_1http://bakery.cakephp.org/articles/Petert/2012/01/30/960_fluid_grid_system_bake_templates_cakephp_2_1Want to use 960 grid system in your baked app? Ever see this "fluid" template that uses it? http://www.designinfluences.com/fluid960gs - I put it into some bake templates.It's not that I don't like the default baked views, but I wanted something more generic and flexible. This template is extremely fast to work with too. You can add more boxes and other content very easily as opposed to the def...SnippetsMon, 30 Jan 2012 20:09:11 +0000jQuery Multi-input for CakePHP http://bakery.cakephp.org/articles/menone/2012/01/12/jquery_multi-input_for_cakephphttp://bakery.cakephp.org/articles/menone/2012/01/12/jquery_multi-input_for_cakephpmen__1@mail.ru for any questions<h2>Code for view:</h2><pre>&#060;?phpecho $this-Html-script;echo $this-Html-script;echo $this-Form-create;echo $this-Form-input;?&#062;&#060;div id="multi-input"&#062; &#060;?php echo $this-Form-input; echo $this-Form-input; ?&#062;&#060;/div&#062;&#060;?phpecho $this-Form-end;?&#062;&#060;script&#062;$ { $.multinput;});&#060;/script&#062;</pre><h3>Options for plugin:</h3><ul><li><b>myPag</b> - Object for paginator. If not passed, the paginator will be posted after the curr...</li></ul>SnippetsThu, 12 Jan 2012 08:33:34 +0000Override/Extend Core Acl Component and DbAcl Classhttp://bakery.cakephp.org/articles/cakemonster/2011/11/03/override_extend_core_acl_component_and_dbacl_classhttp://bakery.cakephp.org/articles/cakemonster/2011/11/03/override_extend_core_acl_component_and_dbacl_classTHE PROBLEMWhile developing my application I decided to add some custom fields to my aros_acos permissions table. The extra fields were needed to provide an audit trail and also were needed by a custom function that automatically rebuilds the aros, acos and aros_acos tables while preserving existing permissions. This allowed me to continue to develop the application after it had been published ...SnippetsThu, 03 Nov 2011 01:56:04 +0000Cakephp breadcrumbshttp://bakery.cakephp.org/articles/energoso/2011/08/23/cakephp_breadcrumbshttp://bakery.cakephp.org/articles/energoso/2011/08/23/cakephp_breadcrumbs<?php// THE HTML HELPER NEEDS TO BE ENABLED FOR THIS TO WORK!print_r;// USAGE EXAMPLEforeach{ echo $html->link;}?>SnippetsTue, 23 Aug 2011 13:39:38 +0000CakePHP CSV export Controllerhttp://bakery.cakephp.org/articles/lsiid9/2011/08/10/cakephp_csv_export_controller_1http://bakery.cakephp.org/articles/lsiid9/2011/08/10/cakephp_csv_export_controller_1<pre>/** * * Dynamically generates a .csv file by looping through the results of a sql query. * */function export{ini_set; //increase max_execution_time to 10 min if data set is very large//create a file$filename = "export_".date.".csv";$csv_file = fopen;header;header;$results = $this-ModelName-query;// This is your sql query to pull that data you need exported//or $results = $this-ModelName-find);/...</pre>SnippetsWed, 10 Aug 2011 19:20:44 +0000Check useragent for mobile devicehttp://bakery.cakephp.org/articles/alvardos/2011/06/28/check_useragent_for_mobile_devicehttp://bakery.cakephp.org/articles/alvardos/2011/06/28/check_useragent_for_mobile_device<code>if ) { define');}function isMobile { preg_match; if ) { return true; } return false;}</code>SnippetsTue, 28 Jun 2011 09:17:34 +0000Optimize URL Generatorhttp://bakery.cakephp.org/articles/luisarmando/2011/07/05/optimize_url_generatorhttp://bakery.cakephp.org/articles/luisarmando/2011/07/05/optimize_url_generatorIt is important to note that each time you put a link in your view, the Router::url method is called and the URL string is computed.Now think about a page full of links, and also you'll see that this URLs have common parts. For example, the typical index actions shows a list rows, and in each row there is a link to edit and delete. The fact is that this links have the pattern /:controller/:acti...SnippetsTue, 05 Jul 2011 11:34:45 +0000Migrationshttp://bakery.cakephp.org/articles/Thaissa/2011/07/01/migrations_2http://bakery.cakephp.org/articles/Thaissa/2011/07/01/migrations_2<p>Everybody knows how hard is to keep a database up-to-date, when you work with more than one programmer at the same time, in the same project. On my company, we started to use a directory, containing all .sql files, with CREATE TABLEs, INSERTs and UPDATEs. But today I thought that we could make it even better to manage them.</p><p>I read about CakePHP's migration script, but just couldn't make it work....</p>SnippetsFri, 01 Jul 2011 01:28:03 +0000Update ARO alias on savehttp://bakery.cakephp.org/articles/carbontwelve/2011/05/26/update_aro_alias_on_savehttp://bakery.cakephp.org/articles/carbontwelve/2011/05/26/update_aro_alias_on_save<p>If you look into the default AclBehavior here you can see around line 98 to 100 that it saves all other fields relating to the ARO except for its alias. While there are countless ways around this, I quite like the fact that the AclBehavior nicely ties in with Auth without too much extra code. Therefore to fix this I decided to write my own extension to the AclBehavior that could be simply inser...</p>SnippetsThu, 26 May 2011 13:58:15 +0000Redirect all 404s to Index Page in Cake PHPhttp://bakery.cakephp.org/articles/opelin/2011/05/07/redirect_all_404s_to_index_page_in_cake_phphttp://bakery.cakephp.org/articles/opelin/2011/05/07/redirect_all_404s_to_index_page_in_cake_php<code>class AppError extends ErrorHandler { function error404 { // redirect to homepage $this->controller->redirect; }}</code>SnippetsSat, 07 May 2011 12:17:26 +0000SQL Dump Task for Shellshttp://bakery.cakephp.org/articles/carcus88/2011/04/08/sql_dump_task_for_shellshttp://bakery.cakephp.org/articles/carcus88/2011/04/08/sql_dump_task_for_shellsWhen using shells there is no standard interface to dump out your SQL queries like there is in the controller. To do this I have created the SqlDump task that you can use in your shell. This code was taken directly from the built in cake\libs\view\elements\sql_dump.ctp code. You can use it to get a dump in array format or have it create a .csv file.[code]?php/** * SQL Dump Task. Dumps out SQL l...SnippetsFri, 08 Apr 2011 20:10:14 +0000CakePHP - Quick record actionshttp://bakery.cakephp.org/articles/edithgarcia/2011/03/28/cakephp_-_quick_record_actionshttp://bakery.cakephp.org/articles/edithgarcia/2011/03/28/cakephp_-_quick_record_actions<code>function quick_actions { $action = $this-data[$form]['actions']; App::Import; $this-DynamicModel = new $form; if { foreach { if { $this-DynamicModel-delete; $this-Session-setFlash; $return = true; } } } if { foreach { if { if ,array)) { $this-Session-setFlash; $return = true; } } } } if { foreach { if { if ,array)) { $this-Session-setFlash; $return = true; } } } } if { foreach { if { if ,array)...</code>SnippetsMon, 28 Mar 2011 08:28:41 +0000Display TYPO3 content using CakePHPhttp://bakery.cakephp.org/articles/olav/2010/09/22/display-typo3-content-using-cakephphttp://bakery.cakephp.org/articles/olav/2010/09/22/display-typo3-content-using-cakephpAccess the software at http://schettler.net/fossil/t3c and take part in this exciting new way to build TYPO3 backed websites. The software has the following properties[ulist][li]No TypoScript used[/li][li]Can display almost all content types from the TYPO3 demo installation, using standard CakePHP view elements. The set of content types supported is continuously being updated. Patches welcome![...SnippetsWed, 22 Sep 2010 09:05:12 +0000Robust crypt functionality for use in CakePHPhttp://bakery.cakephp.org/articles/ndejong/2010/09/20/robust_crypt_functionality_for_use_in_cakephphttp://bakery.cakephp.org/articles/ndejong/2010/09/20/robust_crypt_functionality_for_use_in_cakephp[b][p]Catch the updated and easier to use CryptClass at Github here:-[url]https://github.com/ndejong/CryptClass[/url][/p][/b][p]The most common scenario is that where you need to pass application state around that involves data that you do not want users to see or tamper with. If you are dealing with your own application you would just use a user session data-store or encode it an drop it into ...SnippetsMon, 20 Sep 2010 06:49:09 +0000Use different configs for different environmentshttp://bakery.cakephp.org/articles/stevena0/2010/08/29/use-different-configs-for-different-environmentshttp://bakery.cakephp.org/articles/stevena0/2010/08/29/use-different-configs-for-different-environmentsSo, my method works in a similar way to Rails, by using an environment variable to set the current environment , and loading the corresponding config file.This means you can keep your production config in version control, and not have to edit it on your live servers. You just deploy however you normally would , and the live config is updated - much nicer in my opinion.To get this to work, add t...SnippetsSun, 29 Aug 2010 02:52:10 +0000jQuery image upload & crophttp://bakery.cakephp.org/articles/klagoggle_myopenid_com/2010/08/25/jquery-image-upload-crophttp://bakery.cakephp.org/articles/klagoggle_myopenid_com/2010/08/25/jquery-image-upload-crop[h3]Requirements[/h3][ulist][li]PHP 4 or Higher [/li][li]PHP GD Library[/li][li]jQuery[url]http://jquery.com/[/url][/li][li]Image Area Select plugin - [url]http://odyniec.net/projects/imgareaselect/[/url][/li][/ulist][h3]Installation[/h3]Ok, now we must create a new Component called "JqImgcrop".Let`s create a new file called "jq_imgcrop.php" in yourapp/controllers/components/ with following con...SnippetsWed, 25 Aug 2010 12:20:44 +0000Simple XML-RPC Services Implementationhttp://bakery.cakephp.org/articles/jayesh/2010/08/23/simple-xml-rpc-services-implementationhttp://bakery.cakephp.org/articles/jayesh/2010/08/23/simple-xml-rpc-services-implementation[b]STEP 1:[/b]Download a XML-RPC server implementation library. I used my favorite library "XML-RPC for PHP" written by Edd Dumbill, Gaetano Giunta, Miles Lott, Justin R. Miller, and Andres Salomon. It comes with extremely well written documentation and sample files. You can download the library from http://phpxmlrpc.sourceforge.net/I have used 3.0.0beta for this tutorial.[b]STEP 2:[/b]Copy [i]...SnippetsMon, 23 Aug 2010 15:55:05 +0000