• RSS
  • Email
  • Twitter

Yahoo Search BOSS as a CakePHP Plugin

Posted by Matt on Tue, Feb 10 2009

In the CakePHP digest I posted the other day I linked to Neil Crookes' CakePHP datasource for using Yahoo! Search BOSS. BOSS stands for Build your Own Search Service and is a cool way to integrate search directly into your app.

I mention that Neil's code would make a really cool plugin. This sparked a discussion as to whether this was possible with Cake's current plugin architecture.

The issues where:
1) How to get the datasource configuration, which would normally go in /app/config/database.php
2) How to reference the datasource class itself.
3) How to handle the custom route.

I was able to knock off the first two. The third one isn't possible without altering the base route file (/app/config/routes.php), but by renaming the controller and action I got the default route looking pretty good. Here are the changes I made to Neil's code.

Made It Into A Plugin

I moved all of Neil's code into /app/plugins/yahoo_boss. Then I created YahooBossAppModel and YahooBossAppController which are just empty classes, but are required for plugins if you want to access them from a URL. I then altered the controller and model to extend those classes.

Handling The Datasource And Config

Cake allows you to add datasources using ConnectionManager::create, so I figured I could use this from anywhere in the plugin to setup the datasource. First thing I needed was to load the config class. Since database.php already has a DATABASE_CONFIG class I would need to use a different name. I went with YAHOO_BOSS_CONFIG and put it in /app/plugins/yahoo_boss/config/yahoo_boss.php.

Now I needed to manually load this file so the class was accessible. I did an quick test with php's include to make sure this would work, but then moved to Cake's App::import.

App::import(array('type' => 'File', 'name' => 'YahooBoss.YAHOO_BOSS_CONFIG', 'file' => 'config'.DS.'yahoo_boss.php'));

I'm open to suggestions if there is a cleaner way to do this. I also needed to load the datasource itself from /app/plugins/yahoo_boss/models/datasources/yahoo_boss_source.php.

App::import(array('type' => 'File', 'name' => 'YahooBoss.YahooBossSource', 'file' => 'models'.DS.'datasources'.DS.'yahoo_boss_source.php'));

Then it was just a matter of creating an instance of YAHOO_BOSS_CONFIG and using that to add the datasource to the ConnectionManager.

$config =& new YAHOO_BOSS_CONFIG();
ConnectionManager::create('yahooBoss', $config->yahooBoss);

I put all this code in the constructor for the search model.

Dealing With The Routes

This issue isn't fixable at the moment. There is no way to inject routes from a plugin. So instead I renamed the controller and action so that the default route was a bit more friendly. The user still has the option of changing the route by editing their routes config, but it isn't really necessary.

First I renamed the controller from "searches" to "search". Yea, it doesn't really follow the Cake convention...oh well. Then I moved the results action to index. This allows the search to be accessed at "/yahoo_boss/search". Not bad. I re-added the results action, which basically just points to the index action. So after a search the url will be "/yahoo_boss/search/results/term:whatever". Again, not perfect, but pretty good.

Wrapping Up

Again all the original code is from Neil Crookes originally posted on his blog. This was mostly an exersize to see if it would be possible to move it to a self contained plugin. You can see it in action here or some results here. That demo is setup to search this blog. All the code is availabe in GitHub.

Posted in CakePHP | 8 Comments

CakePHP Digest #7 - The Rise of the Plugin

Posted by Matt on Mon, Feb 09 2009

News

CakePHP has really cool, and underutilized plugin system. It looks like the underutilized part is starting to change as there are some neat examples of the power of plugins coming out lately.

First there is a new CakePHP API and the plugin that generates it, which has been released on TheChaw. Even though the CakePHP core works with PHP4/5, the API generator uses PHP's reflection API, so you're going to need PHP 5.2 or better to run it. Which really isn't a negative unless your stuck on PHP 5.1.6. Yea, I'm stuck using 5.1.6 at work. Seriously, 5.1.6? Come on!

The search kind of stunk when the new API was first launched, but was quickly improved. Although there are still some issues. Like how it can't find the classes by their name. Check out the search for httpsocket class. If only the code for the API was open source, I would totally fix...ah forget it.

For someone who uses the API almost excursively (I hardly ever use The CookBook), the changes are nice. I really didn't have a problem with the old API, but I will say this one seems much faster and the transition was seamless in terms of usability. Hey, anyone remember the old days when selecting text in the API would cause Firefox to freeze and eventually crash?

Anyway, the new API is the work of gwoo and Mark Story. No really, Mark Story was involved - can you believe it? Mark is also on the Twitter now, so follow him up.

In other Mark Story/CakePHP plugin news, the DebugKit is now offically off GitHub and exclusively on TheChaw. The DebugKit also has a new "history" panel, which is the work of pure divine genius. It is hard to say that this new panel was "coded" - a better description would be that it was born forth from a power that transcends all consciousness. So really, there is no reason to not be using the DebugKit.

And if downloading and unzipping is too tedious, John David Anderson, aka _psychic_, aka raisinbread released an early version of a plugin server. Right now there are only a few plugins on it, but it's still pretty cool and shows a glimpse of what is to come.

Tickets and Commits

Commits have slowed down lately, just 10 in the last two weeks. This was to be expected now that the framework has gone stable. Although there are a fair number of open tickets. Five are currently assigned to developers and at least another two that are legit, but unassigned at the moment (#6043 and #6072).

It's kind of sad that tickets have increased 700% since the release of 1.2 stable. This is a bit disappointing as I would expect maybe a 50% increase, tops. You may argue that there was only one ticket immediately post 1.2 release so a 700% increase is misleading plus an increase of 50% would mean there was a half ticket and that doesn't make sense. I would counter by having my mom call your mom and get you in trouble for being mean. So there.

In The Wild

A ton of new sites to mention - almost leads one to think that Cake makes it easy to build websites.

Dan from Lunar Cow Design emailed me a couple sites he built. The first is the International Marine Animal Trainer's Association, whose goal is to "foster communication, professionalism, and cooperation among those who serve marine mammal science." Sounds cool and as long as it means more dolphins playing volleyball for my amusement, I'm all for it. The second site is the Club Plus Network, which didn't meet my dolphin volleyball per page quota, so I lost interest before figuring out what it did.

From DRE via the Google Group comes iTestCars.com, which aggregates the feeds of various car blogs, yet oddly does not have a feed of it's own.

Lennaert Ekelmans wrote a bakery article about how Twittermail.com was rebuilt in 48 hours using CakePHP. I will write more about their bakery article in my forthcoming post "How To Use The CakePHP HttpSocket Lib Instead of curl."

Nate tweeted that the Blue Man Group site uses CakePHP. So if you're a depressed male you should definitely check out this support group.

Another site via twitter. This time from Tarique Sani who tweeted about Bedpost, a site to keep track of you sex life. They make the classic mistake of branding the site "Bedpost" but the domain name is "bedposted.com". Ironically, going to bedpost.com offers "Free Porn - No Bullshit." So really, between the two sites, they pretty much cover everything your love life could need. Heck, maybe you visit bedpost.com by mistake first, then a few minutes later you can log your encounter with Rosie Palm and her five friends on bedposted.com.

Once again from twitter. Oscar Carlsson announces his latest site, letsrace.se.

In The Blogs

The blog section of this digest can be renamed in honor of Neil Crookes, who cranked out three high quality CakePHP posts in the last two weeks - all with code available in GitHub. First up is his HistoryComponent, which tracks a users progress through the site and can be used to redirect them back to previous pages. Next is Neil's CakePHP implementation of Yahoo!'s BOSS, which right now is implemented as a set of files that you drop into your app, but could probably be rolled into a really cool plugin. Lastly is his SequenceBehavior that is used for getting a handle on ordering of records.

Teknoid, who has also been blogging a lot lately, has a nice post about managing baked and scaffolded templates.

m3nt0r has also been churning out the CakePHP posts. He has a post about a really cool blogger who is giving away a copy of CakePHP Application Development and made a strangely addictive timeline of all the #cakephp posts on twitter.

In The Groups

Not to single out any particular thread, but my singled biggest message board/forum/newsgroup peeve is when someone asks a perfectly legitimate question and gets responses either wanting to know why they asked the question or that the question is wrong in the first place. Come on people. Unless the poster made it clear the don't know what they're doing let's assume we're all competent and have our reasons for needing to do things a certain way.

Everyone's second favorite Google Group topic (behind the dreaded framework performance comparison topic) popped up again. Yup, it's the "which editor do I use to code CakePHP" topic.

Also I believe this is the first SVN vs Git thread. Keep a link to it handy, for when this topic comes up again on a monthly basis.

There a couple new plugins that allow to search the API and the CookBook from your Firefox search box. You can find them both here along with some bonus drama.

In general the Google Group seemed really active lately. Much more so then in the beginning of January, which can probably be attributed to holiday hangover. Some other active threads were about the new API and UTF-8 encoding.

In The Bakery

Ronny Vindenes created a helper for same timeline widget that you saw in the #cakephp twitter page above.

Siegfried Hirsch has created a datasource for dealing with CSV files.

With any luck both of the above links will still be valid at the time you're reading this. Yes, that is a veiled shot at my growing annoyance with the Bakery. I understand the need to moderate the content, but it sucks that anytime there is a change in the article the page goes missing until it is re-approved. Do you realize how hard that makes it to write a CakePHP Digest post?!?!?! COME ON!!1!

And on that note don't forget to subscribe to my feed or follow me on twitter.

As always if you think I missed something leave a comment. Or if you do something interesting and want it included in the next digest, send me an email.

Posted in CakePHP | 13 Comments

Giving Away A Free Copy Of CakePHP Application Development

Posted by Matt on Thu, Feb 05 2009

cakephp-application-development

This giveaway has ended. Here's the winner.

I'm not sure if this is going to be frowned upon, but I'm giving away my review copy of CakePHP Application Development (reviewed here). I figure I don't have much use for it, so maybe someone else will benefit.

Book is in A+++ condition, adult owned, read once. I'll pay shipping. All you have to do is leave a comment on this post - although it would be cool if you signed up for my RSS feed or followed me on twitter. On Feb 28th, 2009 Feb 16th, 2009 I'll run some fancy SQL and select one of the comments randomly.

If you already know Cake it probably isn't worth entering as the book is geared towards beginners. I know some of the core devs spend so much time coding the framework they probably couldn't code with the framework (you know who you are), but please refrain from entering.

Good luck!

Posted in CakePHP | 43 Comments

Update To My Fork Of The CakePHP DebugKit

Posted by Matt on Mon, Feb 02 2009

I blogged (and screencasted) before about some of the changes I made to the CakePHP DebugKit. At the time it only worked with the jQuery lib, but I just committed an update so that my changes now work will all the JavaScript libs and the version that runs without a library. I don't really know the other libraries very well, so my code may not be optimal or it may suck outright.

Also the plain JavaScript version was a nightmare. Do people actually write JavaScript without a library? I would rather be the cameraman on the receiving end of Springsteen's crotch slide from the SuperBowl halftime show, then write plain JavaScript.

If you saw the screencast you saw how the DebugKit is now storing a history of requests. This data has to be saved somewhere and I was initially torn on how to do it. I ruled out using a database right off the bat. That left the session or a file. I initially went with the file approach, but then realized if I used one file that there was a the possibility that multiple people could be hitting the same app instance and it would completely confuse things. Granted, most times the DebugKit will be in use by a single developer working on their own sandbox. I ended up just stuffing everything in the session. Which seemed to work ok, but left the outside possibility that polluting the session could mess up the app.

So rather then make the decision for everyone, I added an option that lets you decide. When including the DebugKit set the 'historyStorage' option to 'file' or 'session'. The default is session.

var $components = array('DebugKit.Toolbar' => array('history' => 10, 'historyStorage' => 'file'));

As you can see you can also set how many requests to keep - defaulting to 5.

Once again the code is available at http://github.com/mcurry/debug_kit/tree/master. Most of my changes have been rolled into the official version (or Mark has implemented his own fixes, which are better anyway). So stick to the official version at http://thechaw.com/debug_kit. If you're having trouble downloading the zip, just keep hitting it. GitHub has some issues, but eventually it will work.

Posted in CakePHP, Code | 9 Comments

Check Out These Upgrades I Made To The CakePHP DebugKit (in screencast format)

Posted by Matt on Thu, Jan 29 2009

UPDATE: The changes below have all been merged into the official DebugKit. You should definitely use that version.

I've been doing some upgrades on the CakePHP DebugKit and wanted to share them with everyone. I figured doing a quick screencast would be faster then writing a post. Was I wrong. It took me like an hour to record this, even though the running time is just over two minutes. The code is available at http://github.com/mcurry/debug_kit/tree/master. Most of my changes have been rolled into the official version (or Mark has implemented his own fixes, which are better anyway). So stick to the official version at http://thechaw.com/debug_kit. At the moment only the jQuery version is working. Enjoy!

Posted in CakePHP, Code | 11 Comments
10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18

Tags

  • Startup
  • Satire
  • Code
  • CakePHP

Popular Posts

My Sites

  • PlanbookEdu.com
  • RSStalker.com
  • Later.RSStalker.com

My CakePHP Plugins

  • Asset (JS/CSS) Packager
  • Custom Find Types
  • Html Cache
  • JavaScript Validation
  • Site Status Page
  • Static User
Copyright © 2012 PseudoCoder.com, All Rights Reserved.
Powered by Croogo, Built with CakePHP