09 May

Meetup Talk on The CakePHP 3 ORM: Even More Awesome Than You Realize

Another talk at PHP Vegas Meetup., this one covering some of the more interesting aspects of the CakePHP 3 ORM. This was mostly a last-minute modification of what I will present at CakeFest in Amsterdam, in a few weeks, owing to a drop-out of one of our speakers.

I think, this talk was a weaker one for a few reasons. I didn’t have enough time to greatly change the content to better fit with a more general audience that was as highly exposed to CakePHP in general. I also didn’t have enough time or information into why the Cake 3 ORM is better or some of the big differences between it and other ORMs in the PHP world, like Doctrine and Eloquent. All that being said it is highly valuable for me to present this talk in a more comfortable environment at least once before CakeFest.

04 Apr

Lynda Course – Learn CakePHP 3: The Basics

Lynda.com is a website that provides online training courses in a variety of subject materials. I’ve been honored to work with them on now three separate courses. The latest one went up earlier this month, it covers some of the basics of working with CakePHP 3. Interested in working with CakePHP? You should watch the course, learn how easy it is to get started with CakePHP and all that ways that CakePHP is a great web development framework. If you aren’t interested in CakePHP, take a look at Lynda just in general there is probably something of interest for you learn from. Lynda prides itself on producing quality content and it shows both in the courses and in working with them.

You’ll be able to see any new courses I author at lynda.com/justinyost.

16 Apr

CakePHP 3.0, Use It In Pieces

One of the key goals of CakePHP 3.0 as discussed recently was making CakePHP 3.0 more decoupled. CakePHP 3.0 has achieved that goal very nicely. Take a look at the CakePHP organization’s repos on GitHub and you will find a long list of decoupled collections of classes that are all part of the overall CakePHP framework that can be used completely independently of CakePHP itself.

Perhaps you are interested in some of CakePHP’s utility classes, like the Security utility, which are a great resource for hashing and encrypting basic data (not passwords) that you want some amount of reasonable security applied to it. Or perhaps you are interested in CakePHP’s Validation system which provides for validating arbitrary arrays of data. The most complex and most interesting part of CakePHP 3 by far is even available for use independent of the rest of the CakePHP core, the ORM layer.

How about an example to help clarify how to use these different pieces in smaller projects. Let’s build a simple webpage that allows us to submit a contact form request and validate it using the CakePHP Validation Library.

I’m doing this in a new `index.php` file in a new directory. First we need to get the Validation Library in our directory.

$ composer require cakephp/validation

That creates a new `composer.json` and loads the CakePHP Validation package. Next in our `index.php` file we need to load the Composer autoloader and the CakePHP Validation Class.

namespace LoadsysTestValidation;
require dirname(__FILE__) . "/vendor/autoload.php";
use CakeValidationValidator;

Now at this point we can create a new instance of the Validator class and validate arbitrary arrays of data, like what we would get from `$_POST`.

$validator = new Validator();
$validator
  ->requirePresence('name')
  ->notEmpty('name', 'Name is required to be submitted.');
$errors = $validator->errors($_POST);

I worked out a complete example of this and posted it on GitHub as a sample if you need more details or insight into using the CakePHP packages.

The overall CakePHP framework may not be the right choice for everyone in every case. With the recent decoupling of the framework in the 3.0 branch, CakePHP can be more easily used for those times when you want to pick either the very best packages for your problem or you only need a limited subset of features from CakePHP for your web application.

This was previously posted on the Loadsys blog.

12 Feb

Meetup Talk on CakePHP 3.0: The Cake Isn’t a Lie and It Tastes Delicious

I gave this presentation last week at the Las Vegas PHP Meetup, covering some of the new features in CakePHP 3.0. It was a fairly short talk focused mostly on showing off code and some examples of what Cake 3.0 is looking like along with trying to answer some of the questions that I commonly hear inside of this group regarding CakePHP vs. every other framework. The sample project that I built is on Github.

As I give these presentations and watch other people give theirs, I am trying to reflect on them and figure out what works and what doesn’t. One thing that worked for the most part was not trying to write any code during the presentation, instead my idea was to flip through tags in the git repo between hey I did x and look what x did. This wasn’t actually a bad solution but not great. It had the flaw that because I had some changes along the way getting the repo actually working correctly, ignoring tmp folders, etc, when I tried going to a tag and back I would up having to delete changes and basically reset the repo in the process. So partial credit there I think.

26 Sep

Mark Story – Using bcrypt for passwords in CakePHP

CakePHP uses salted sha1 hashes for passwords by default, and has for a while. There has been some talk on the mailing list lately of switching the default hashing to something more secure, such as bcrypt. I think this is a great idea, and will find its way into CakePHP in a future release. Providing a reasonanle upgrade experience is the biggest problem to solve, if the default hashing strategy was to change. One option is to silently upgrading passwords. I’m not a fan of this approach as it has more room to go wrong, and possibly corrupt data. Another option, allowing developers to stick with sha1 if they have passwords hashed with it is a safer and probably better overall option.

While bcrypt is not part of CakePHP just yet, I wanted to see how difficult it would be to start using bcrypt today. Turns out it was pretty simple. Getting bcrypt working only required a subclass of FormAuthenticate and a two line change to the User class.

via Mark Story – Using bcrypt for passwords in CakePHP. Awesome, I tried doing this in CakePHP 1.3 a few weeks ago but couldn’t get it to work right all the time.

28 Jun

Utoxin’s Random Insanity – CakePHP + Symlinks = Pain

Now that I’ve had a day or so to recover, I’m going to tell you about what I just spent 2-3 weeks trying to resolve. By way of explanation, our main product at work is a CakePHP based CMS application. It has a lot of neat features, including the ability for users to upgrade to newer versions any time they choose. We keep all versions present in /etc/precious_core/<version_number>/, and each user has a symlink to the relevant directory in their webroot.

When they upgrade, part of the process is to replace that symlink with a new on that points at their new version. For a long time we’ve known there was a problem of some kind related to CakePHP’s cache that developed after upgrades, but it was never a huge problem, so we mostly just ignored it. However, in a recent release, it started causing major problems, and I got tasked with finding and fixing the actual bug. I figured it would take a day or two, and I’d be done with it. Little did I know just how painful this was going to be.

I initially tried several ways of forcing the cache to get cleared when the app was upgraded. That worked well, as far as it went, but then a new problem surfaced. At least half the time, the cache would re-populate with bad data after an upgrade. Some of the cached file paths would be for the wrong version of the central app, for no apparent reason. I tried throwing even more thorough cache clearing at it. Things got a little better, but it still wasn’t working.

Finally, I fully duplicated our production setup on my local dev machine, parallel version directories included, and installed a PHP debugger, so I could step through the code and figure out what exactly was going on.

via Utoxin’s Random Insanity – CakePHP + Symlinks = Pain. Debugging oh what a joy it is.

18 Jul

CakeFest

CakeFest is the official conference for CakePHP. Thanks to my work with Smartfield in building and launching CropInsight I’ll be attending CakeFest this year in Chicago from September 2nd through the 5th.

CakePHP is a fantastic web development framework that I absolutely love working with every single day. CropInsight is a web application built using CakePHP, jQuery and a whole lot of sweat and time. Not only do I work with CakePHP for my full-time job, I also use it for personal projects, it’s a great tool for PHP developers. Trey Reynolds and I will get to spend time learning more about the inner magic of Cake and hopefully helping the core developers of Cake learn more about one of their users.

Photo Credit from Flickr user: koyhoge.