background preloader

Site Content

Facebook Twitter

15 Essential CakePHP Tips « nuts and bolts of cakephp. Forcing an SQL JOIN in CakePHP « nuts and bolts of cakephp. Update (10/7/2009)… this functionality has been rolled into Habtamable behavior You’ve probably noticed that by default CakePHP will only create a JOIN query if you have a hasOne or belongsTo associations between your models. There are cases, however, when a JOIN is necessary to get just the right data. So how do you tell cake to create a JOIN? Well, you have to rely on some crafty methods, but all in all it’s not very hard, once you get the hang of it… I will summarize here a few tricks I’ve encountered on the google group, so big thanks to the original authors of these ideas. Let’s take our favorite sample models: User hasMany Post and Post hasAndBelongsToMany Tag If we were to do: $this->User->find(‘all’); CakePHP will run a few selects and return you all the User data. So let’s try to force cake to do a JOIN… First things first, we have to make cake forget about our previous bindings between the models: We can use bindModel() to achieve that: So what’s going on here?

SELECT `User`. Like this: Quick Tip - Doing Ad-hoc Joins in Model::find() (Articles) | The. Herewith, a little-known query trick that allows you to do simple ad-hoc joins in your CakePHP finder queries. No binding or unbinding required. Note: This only works if you are using the new Model::find() syntax, which only takes two parameters. If not, please refer to the Cookbook or API.

Part of the "zen" of CakePHP's design is the way in which things are layered. For example, many helper methods take an $options parameter, and methods which are built on top of other methods (think FormHelper or PaginatorHelper) allow you to pass in options at the top level that get passed down to the lower levels, giving you very granular control, even at high levels of abstraction.

So it is with the Model layer. One example I see commonly for this is searching tags, which are joined to a model via a hasAndBelongsToMany association. Controller Class: <? Model Class: <? Public function find($type, $options = array()) { if (! $bind = $options['model'] . '.' . <? Using the Unobtrusive Date Picker Widget in CakePHP (Articles) |

The default CakePHP date selection boxes are rather a pain in the rear. Wouldn't it be nice if you could use a Date-Picker in your app's? Well you can, and it's rather easy to implement. First things first Download and extract the Unobtrusive Date-Picker Widget here: Copy the 'css/datepicker.css' file to 'app/webroot/css' Copy the 'js/datepicker.js' file to 'app/webroot/js' Copy the contents of the media folder to 'app/webroot/img/datepicker' Open the datepicker.css file in your 'app/webroot/css' folder. Using the Find/Replace functionality of your editor replace all occurences of '.. /media' with '.. /img/datepicker' Edit the default view Note: If you do not have a default.thtml file then you will need to create one, for simplicity you can just copy Cake's default one from 'cake/libs/view/templates/layouts' to 'app/views/layouts' and edit the latter.

Put the following before the closing head tag <? <? <? Study Reveals: 13 Best Practices Of Social Media Implemented By. I have noticed in both observing and working with non profits that their uptake and utilization of social media is creative, innovative and extensive and when I came upon this study by the University of Massachusetts Dartmouth Center for Marketing Research who had recently completed (June 2009) one of the first statistically significant studies on the usage of social media by United States charities that my anecdotal suspicions were supported by empirical evidence. The new study compares organizational adoption of social media in 2007 and 2008 by the 200 largest charities in the United States as compiled annually by Forbes Magazine.

For complete details on Forbes Magazine’s list of the largest charities, please visit their website at Forbes.com. They are some of the best-known charities in the country including the Salvation Army, American Red Cross, Catholic Charities USA, Habitat for Humanity International and Easter Seals. Conclusion 226inShare. Google Real Time Search and your Charity | general | social-news.