Posted by Kjell in GeneralMay 17th, 2009 | No Comments
Ever since i heard of Sprockets on Twitter i wanted to use it in my apps. Unfortunatly i am not into Ruby.
Sprockets is a Ruby library that preprocesses and concatenates JavaScript source files. It takes any number of source files and preprocesses them line-by-line in order to build a single concatenation. - getsprockets.org
I wanted to port it to PHP or find clever ways to use it in CakePHP (shell?). But before you start something like this you should check if there isn’t already a project and so i found PHPSprockets from Stuart Loxton. PHP Sprocket is a port of Sprockets. Cool.. so the...
Posted by Kjell in CakePHP HintsApr 24th, 2009 | No Comments
Don’t mess wit teh formz.
I thought it’s cool to disable a field simply by using the disabled Element property. Being distracted by other parts in the app i just applied it and left it alone - “How can this be bad, right?”. After some more time i did test the form again and found myself being blackholed all of a sudden - whaaa? - Took me some time to find out what the problem was (grrr).
Here’s the reason
If you disable a field using Javascript, the field name and its value never reaches the server. This of course invalidates the Security Token and thus leads to a...
Posted by Kjell in GeneralApr 24th, 2009 | 2 Comments
This helps if you have trouble with missing /usr/libexec/ssh-askpass on Leopard. It’s quiet annoying but i found the following shell script and it works perfect for Textmate and probably all other places. This includes not just passwords but also the yes/no for the remote fingerprint question.
#! /bin/sh
#
# An SSH_ASKPASS command for MacOS X
#
# Author: Joseph Mocker, Sun Microsystems
#
# To use this script:
# setenv SSH_ASKPASS "macos-askpass"
# setenv DISPLAY ":0"
#
TITLE=${MACOS_ASKPASS_TITLE:-"SSH"}
DIALOG="display dialog \"$@\" default answer \"\" with title \"$TITLE\""
DIALOG="$DIALOG...
Posted by Kjell in CakePHPApr 18th, 2009 | 2 Comments
As promised in the comments of the most recent entry i created a repo for my event system.
It’s currently under heavy development, yet ready to use. I don’t think the interface will change much from here on out. The installation is similar to the DebugKit. Put the “eventful” plugin into your plugins folder and add the Behavior or Component to your app. This will include all dependencies and the system is ready to use.
Only one thing is different from regular plugins. There is a seperate “events” folder which is a empty layout for the system and the place for...
Posted by Kjell in CakePHPApr 14th, 2009 | 3 Comments
As a follow up to: Events in CakePHP - I really like it
Let’s say you have unkown entities in your project - totally dynamic. Let it be a plugin, another model, not associated at all. Getting new functionality into an existing app can be a pain.
Events do help alot in this case, depending on how you layed out the triggers. Events notify all possible candidates (”can u handle?”) every time something interesting is happening, like “user logged in”, “new image was uploaded”, “post has been edited by xyz”, and so forth.
In this post i want to...
Posted by Kjell in CakePHP SnippetsApr 13th, 2009 | 4 Comments
Currently i use the scaffold views alot to bake a simple admin interface. What annoyed me was that ‘empty’ is not set on select inputs. I could of course go through all add/edit views and add it, but i thought i rather modify the result to include a empty entry.
Always add a “empty” entry to the result
function find($conditions = null, $fields = array(), $order = null, $recursive = null) {
if (is_array($conditions)) {
return parent::find($conditions, $fields, $order, $recursive); // old interface
} else {
switch ($conditions) {
case 'list':
$result = parent::find($conditions,...
Posted by Kjell in CakePHP, CakePHP SnippetsMar 17th, 2009 | 3 Comments
Not sure why, but this ActiveRecord thing appealed to me and so i wrote a short behavior (nothing to release, really..) that kinda emulates RoR a little more… However, i think this is something for the bin. Or does anyone see a need or benefit of something like this:
$this->User->find('first');
pr ($this->User->record); // has the full record
$this->User->record->username = 'BlaBlubb';
$this->User->record->email = 'bla@blubb.com';
$this->User->save(); // saves full record
$this->User->find('first');
pr ($this->User->record); // jup, that worked.
Useful? hmm.. maybe. It was fun to explore...
Posted by Kjell in CakePHP SnippetsMar 14th, 2009 | 3 Comments
It’s not that i did not know what else to post, but here’s a more general approach for those who like using blackList over whiteList when tighten up save() calls.
This post is ment as follow up to the one teknoid posted. Instead of doing the array_diff stuff in your controller, you could do it in the model (respectively, all models). So here it goes. I made the $blackList part optional, but feel free to change that.
class AppModel extends Model {
function save($data = null, $validate = true, $fieldList = array(), $blackList = false) {
if (!empty($fieldList) && $blackList)...
Posted by Kjell in CakePHPMar 13th, 2009 | 5 Comments
Some time ago in a galaxy far far .. i was thinking about how i could read the Cookbook on my iPhone more easily. Creating a static copy in some custom format? Yes, but the options are really limited and mostly painful:
PDF - Most, if not all, readers suck. (And there’s no pdf version either)
HTML - Yeah right.. why not just use super-tiny Safari then.
DOC - Possible.. if there would be good converters. etc..
Well, you get the idea. It all smells somehow..
Really, really wanting it regardless i jumped into my IDE and wrote a small content grabber in CakePHP which extracts the Cookbook pages...
Posted by Kjell in CakePHPFeb 8th, 2009 | 1 Comment
This is original sunday evening fun stuff!
I’ve found the Timeline Javascript via the german Cakery weblog and was curious about the name and functionality. While looking at the examples it straight hit me. This would be cool for Twitter!
Walking through the examples i hacked an data adapter for the Twitter JSON response. With some more tweaks, like adding the Twitter Icon and colors, i build something that is monitoring the #cakephp hashtag and delivers the 200 most recent tweets in a beautiful scrollable timeline!
See it in action here
Spread and enjoy :)
PS: might break in browsers other...