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.

08 Jan

Meetup Talk on PHP: The Right Way

Think of this is a continuation of the topic from November (that one a PHP Classes 101), this one focused on the site http://www.phptherightway.com/ and other tools to help developers build PHP apps the “Right Way”. I also mentioned both The League of Extraordinary Packages as well as PHP-FIG.

Next month at the Las Vegas PHP Meetup, I’ll be speaking again on CakePHP 3.0 which just came out in RC 1, about a week ago.

06 Nov

Meetup Talk on PHP Classes 101

I presented at this week’s Las Vegas PHP meetup on PHP Classes and Object Oriented Programming. I did a quick run through of both the basics of OOP and how PHP classes and objects work. If you’ve done PHP OOP for any length of time most everything will be commonplace. Though I did add a bit about SOLID and we had a good discussion on the visibility of properties and methods that was useful for even an experienced user.

Each time I present the feedback says it goes better each time. I’m coming down hard against trying to either present code (outside of slides) or actually live code during a presentation. At least today, in the future after I’ve done this dozens of times I might change it up.

07 Jun

Presentation on Unit Testing Inertia

I gave a talk on Tuesday at the Las Vegas PHP Meetup Group titled Unit Testing Inertia.

The basis of the talk was getting over the inertia in writing tests in either a pre-existing application or just getting started writing unit tests in general. It went over very well with a good question and answer session afterwards. While I didn’t spend as much time prepping for this talk, I was comfortable enough with the material (and helped there was no code involved) that it was a solid presentation.

The short summary of the talk is for every new method/bug-fix/feature written, write a test for something else at the same time, and start with the stuff that is easier to test.

I’ve been going through a few different pieces of software for writing and displaying my presentations and this is the first time I’ve been really happy with the tool-chain. I used Deckset, which is a Markdown based presentation system with some great looking styles.

Humorous aside, my spelling is atrocious and even though I had to type out “inertia” dozens of times I misspelled it every time and even just now writing this up, I misspelled it every time.

07 May

10 Years

So for the tenth anniversary, the Zen Garden is open for business once more. I’ve thrown the codebase on Github, given the dusty copy a refresh, started the conversion of the site to HTML5, and brought all of the existing designs kicking and screaming into the modern age. The work isn’t done yet, but it’s a darn sight closer to what how we would build it these days. If you see an area that needs help, consider sending a patch.

Hello CSS Zen Garden, it’s been awhile.

07 May

Line Clampin’ | CSS-Tricks

You want X lines of text. Anything after that, gracefully cut off. That’s “line clamping” and it is a perfectly legit desire. When you can count on text being a certain number of lines, you can create stronger and more reliable grids from the elements that contain that text, as well as achieve some symmetric aesthetic harmony.

There are a couple of ways to get it done, none of them spectacular.

If you are doing Web Design/Development as a full-time and aren’t reading CSS-Tricks, you really should be. Awesome little tricks like this one..

07 May

Google’s Buildings Hackable

We reported this issue to the Google Vulnerability Rewards Program (VRP). After much heckling from my former colleagues at Google, they quickly pulled this system offline. We also applaud Google for creating a program like the VRP and giving us the chance to share our story with a wider audience. At the time of this blog post, this exact issue affects tens of thousands of devices on the Internet and thousands of different organizations. Thank you Google for helping us raise awareness on this issue! I asked that any proceeds from the VRP be donated to the Wounded Warrior Project, but apparently this issue doesn’t qualify for VRP rewards.

If you have a corporate campus or a modern building of any sort… you’re likely running similar systems someplace on your network. We’ve already discovered over twenty five thousand of these systems facing the Internet… one down, twenty four thousand, nine hundred, ninety nine to go 🙂

If Google can fall victim to an ICS attack, anyone can.

Hacking systems that control a building infrastructure.

06 May

Senate passes Internet sales tax in final vote, 69-27

The US Senate passed an online sales tax in a vote this afternoon after a heated final round of debate. A small group of anti-tax Republicans, as well as Democratic Senators from states without sales tax like Montana and Oregon, argued vociferously against the bill—but to no avail.

The final vote was 69-27, not much different than the 74-20 procedural vote that took place two weeks ago. The proposal has hardly changed at all in two weeks. The Marketplace Fairness Act, S.743, would allow states and localities to make Internet retailers collect sales tax from their customers if they do more than $1 million per year in out-of-state online sales.

The bill would allow states to write laws that would force e-commerce businesses to collect sales taxes. Right now consumers are supposed to keep track of any online sales and then report them to their state government and pay sales tax on the purchase. It still has to go through the House where passage is a little more rough but don’t be too shocked if in a few months you have to start investigating adding sales tax to any e-commerce software.

30 Apr

Hex Color Tool

I needed a tool that either added white or black to a hex color. Launching Photoshop just to drag a color picker around wasn’t cutting it. I looked around for a web app that would do this but unfortunately most good programmers are terrible designers. I built HexColorTool to fill the gap. It’s responsive too! Launch it on your smartphone or tablet and use it as you please.

Just added it to my list of web design tools, I know I’ve needed something like it more than once.