debuggable

 
Contact Us
 

10 Days of free Dessert! (CakePHP Tips)

Posted on 13/9/06 by Felix Geisendörfer

If you have been following this blog since it's beginning in early January this year, you probably know that I was posting a lot more short and easy to adapt tips back then.These days I write a lot of lengthy and pretty specific articles that are not useful to quite everybody out there and sometimes take long to write.

For that reason I'm announcing the "10 Days of free Dessert!". This basically means that I'll post at least 1 useful and easy to adapt CakePHP tip begining tomorrow for the next 10 days. I will try to pick things you might not have heard before and that didn't get a lot of loving from the docs team so far ; ).



In case I break my promise and miss only 1 day of posting a new tip (my time zone is GMT+1), I'll take & post a picture of myself putting my face into a cake.

So this last part should make sure I'll stay with it, even so some of you might wouldn't mind if I miss day 10 ; ).

I hope you guys are going to enjoy it.

--Felix Geisendörfer aka the_undefined

 
&nsbp;

You can skip to the end and add a comment.

Christian Tietze said on Sep 13, 2006:

Good idea! I think Cake needs people that write short posts regularily. Your tips are nice etc., but thery're not frequently enough to be a reliable source of tips, at least for me. Hearing about something that I can discover further by myself every day would be just a lot cooler :)

Tom said on Sep 14, 2006:

Nice idea Felix,

DDOS Attack on your blog would be funny these days, wanna see you caked! :D
But, on the other hand, i cant wait on useful cake related stuff, so... :P

jtreglos  said on Sep 14, 2006:

Please, OMG please, miss a day and cake your face for posterity ! You'll give us the missed tip on the 11th day ;)

Felix Geisendörfer said on Sep 14, 2006:

Tom: DDOS Attack, ...? Don't do that! That's rude : p. In that case I'll find out the person responsible for the attack and make sure he's the one in the picture with the cake ; ).

jtreglos: Well, I'm not going to fail my 10-day challenge just for that *g*. However, maybe I'll give you guys another chance to get a picture like that afterwards ; ).

[...] A neat function I just discovered while looking for a useful CakePHP tip to save me from putting my head into a cake is contained in the NeatString class which rests in /cake/libs/neat_string.php [...]

Dan  said on Sep 15, 2006:

Felix,

Great "dessert" series so far. Thanks for taking the time to put up these little tidbits. I'm sure they'll be a great resource for everyone.

I'm not sure if you already have all of your "desserts" planned out but if you need an idea for a new one I'd like to suggest "working with hierarchical data". This seems to be something that many people have had a problem with on the Google group and have never gotten a solid solution for. I'm currently wrestling with this issue myself and I can't find a solid way to deal with a list of categories that are stored as a hierarchy.

There is a solution on CakeForge but its pretty difficult to wrap your head around. Maybe you'll have more luck in interpreting it and post a tutorial on it someday.

Anyway, thanks again for the desserts and keep em' coming...

- Dan

Felix Geisendörfer said on Sep 16, 2006:

Hey Dan, no actually I've not planned out the entire series so far and I appriciate any idea on it. Your suggestion could be quite time consuming but I'll consider it. But let me ask you this up front: Did you try the Cake-native findAllThreaded or did you look at the MPTT stuff for ACL? Because at least as far as the findAllThreaded stuff goes I was able to work with it fairly easily. Oh and there is also an association trick you can use to build hiarchies. Let me know what you've tried out so far ; ).

Dan  said on Sep 16, 2006:

Whats up Felix,

I actually did try the findAllThreaded() method. Worked like a charm in terms of loading the hierarchy into an array. The problem for me came when I was trying to figure out how to traverse the array and find specific data.

For example, one of my hierarchies might look like this:

Computers
Internet

Programming

PHP

CakePHP

Which ideally would result in a friendly url like this:

mydomain.com/browse/computers/internet/programming/php/cakephp/

I couldn't figure out how to take that url and walk through the array until I ended up at the last category "CakePHP" in order to get its id and pull all relevant content.

I also got stuck when trying to find a path by id.

For example, if I know that my CakePHP category has an id of 6, I would need to find the path below it in order to create a link to that category. So lets say a function called:

function getCategoriesBelow()

Dan  said on Sep 16, 2006:

...continued, sorry I hit tab and then enter by accident.

function getCategoriesBelow($id, $categories) {
// will return something like:

// /computers/internet/programming/php/

// Maybe return the subcategories in an array?

}

findAllThreaded() works great. Ideally a set of utility functions for working with the array that findAllThreaded() returns would be incredible.

Now THAT would be some tasty dessert in my book.

Felix Geisendörfer said on Sep 17, 2006:

Hey Dan: Ok in order to resolve the ID of the last category in a list like "/computers/internet/programming/php/cakephp/", you split this string into pieces so you have an array containaing "computers,internet,programming,php,cakephp". Then you start with the last item "cakephp" and query your datbase to get a list of all entries with this name. Then for all entries returned you get the item with the id of your current items parent_id. If one of those has the name of your 2nd item "programming" you repeat the entire process until you either have reached the last item and the category chain exists like this, *or* some link is missing and you display an error.

Alright, now for displaying all sub-items of an item with a known ID, you cannot easily use findAllThreaded. You'll probably have to use findAll() and then write a recursive function that builds your array.

Maybe if I find some time I'll try to cover this topic in the series, let's see.

PHPDeveloper.org said on Sep 18, 2006:

Felix Geisendorfer's Blog: 10 Days of Free Dessert!...

...

[...] For those of you who have followed this site in the past days you might have noticed that I was writing a lot of posts on here recently. This of course has something to do with my 10 Days of Free Dessert! series, but on saturday and sunday both, I wrote 3 desserts even so the bet just says I got to write 1 / day. [...]

[...] I still can’t believe it, but somehow I forgot to post a new dessert yesterday, and therefor lost my bet. I could start whining about all the bad circumstances and how I did several posts on some days, but no. For a brief moment I was also considering to manipulate the date on a new post, but not only that you guys would be way to clever for this kind of cheat, I also felt it would be wrong to do so; ). [...]

[...] Not too long ago, I made a promise to you as my readers. I promised that I would post one useful tip regarding the excellent CakePHP Framework every day for a period of 10 days. I also said what I would do if I would miss one day of posting: [...]

This post is too old. We do not allow comments here anymore in order to fight spam. If you have real feedback or questions for the post, please contact us.