CodeIgniter + Twig = Quick n Dirty ™

In full disclosure, I’m not completely new to CodeIgniter, having built a few freelance projects using the 2.x framework in the past due to it’s speed, flexibility and well-rounded core. It provides a great jumping-off spot for basic PHP-based projects that can benefit from a MVC framework without all the cruft you find in things like CakePHP, Laravel, and Symfony. Another selling point is that in several framework shootouts, CodeIgniter consistently comes in with faster non-cached response times.

Interesting bit of news on a tangent, apparently it is now even more of a community-driven project since October 6, 2014, when the British Columbia Institute of Technology took over stewardship from Ellis Lab, the creator of the framework (and the underpinnings for its ExpressionEngine CMS).

OK, back to CodeIgniter and templates… I was recently working on a little side project that the maintainers wanted to be able to manage all CI templates, but they were not very PHP-savvy. This kind of ruled out the core CI view templates as they are pretty much eval’d PHP files with global variables defined by the calling code. I started off using the built-in template library provided with CI, but quickly realized it was providing nothing more than variable substitution. What I really needed was something that could also provide basic control logic as well, but not require someone to know PHP. I also wanted to use something widely adopted in the web dev community in order to give the project some longevity. What I settled on was Twig.

Twig is the template engine used by Symfony (yeah, I fully realize I dissed that framework a tad earlier) and provides a rich set of template features which can be used for something as simple as variable substitution to something as complex as template inheritance. The nice thing is it’s written purely in PHP and can be used standalone outside of Symfony. After some quick research, I discovered that Bennet Matschullat had already implemented a library for CodeIgniter 2.x to provide full integration with Twig. Happy dance!

To use it, download and extract the GitHub project into your CodeIgniter docroot (it places files in the correct places under the application folder) and download the latest Twig and extract it under application/third-party so the parent directory for the library is named Twig. Then in your controller output function, instead of invoking $this->load->view() or $this->parser->parse(), add the following lines:

That’s it!  The library will invoke the template, cache the compiled version, and return the output from Twig via the normal CodeIgniter output object used by the core view and template mechanisms.  Nice!

Project LiveWire – First Impressions

20141011_104258-1

So, it’s not every day at 10:15a sharp I am sitting astride a prototype motorcycle that could be a game-changer.  The manufacturer? Harley-Freakin’-Davidson. The bike? Project LiveWire.

20141011_104258

I spent seven years in the powersports business in a previous life, and have seen my share of factory prototypes and electric motorcycles, scooters and ATVs. The Project LiveWire Tour took the experience to a whole other level. The staff were friendly, well-organized, and my ride began exactly when it was scheduled to do so.

And did I mention the bike?

20141011_095817

There are a lot of H-D purists out there that are dissing – and dismissing – the LiveWire bike as not a “real Harley,” similar to the way they treated Buell and even the V-Rod whose engine was designed by Porsche. I find this a real shame as we should never discourage an American company from being bold, adventurous, and trying new things. I come from a sport bike background (Honda and Ducati) and applaud H-D for not shirking from the project, and in fact embracing it wholeheartedly.

Enough of my proselytizing, on to the bike and ride!

20141011_102233

After a short intro video explaining the major differences from a conventional motorcycle and what to watch out for, we were led to our group of bikes. The groups were only six total including lead and follow riders, so nice and small with no lag issues you get in larger groups.

When you first “fire” up the bike which consists of pushing a button, the display’s status screen opens, runs a self diagnostic, and then asks you which mode you want – economy or power. Yes, I picked power (note the orange mode on the right of the display). What else did you expect me to pick? The deceptive thing about LiveWire is that the whole time there are no sounds, just a changing display. You’re on a bike, where is all the rumbling and vibration? Nada. When the staff warns that the bike is live and to not touch the throttle until we’re ready to depart, and it’s totally quiet, you realize you are sitting on top of something special.

s-1011102335278

When we take off in standard staggered formation, I realize that for the first time I can hear everything – the wind whistling on my helmet, the tires on the road surface, even the brakes engaging. The power – my God, the acceleration! It’s instant, incredibly aggressive, and like nothing I’ve ever ridden on or in. I don’t think I ever totally twisted the throttle WFO the whole ride, and we punched it hard more than a few times out of stops or exiting curves. At 460 lbs, it’s not a light bike by any means, but handled well and felt solid. In some ways it actually felt better balanced than my trusty Ducati 900Sport, which is saying something. The riding position is more a standard-up type, which felt very comfortable. Also of significance is the seat sits lower than most standard or sport bikes, and with a 29-inch inseam I was easily able to flatfoot in my riding boots. Kudos to H-D for acknowledging that not everyone who rides non-chopper-style bikes is 6 feet tall.

Overall impression? It’s a great bike! Keeping in mind these are hand-built prototypes and don’t have final marketing-approved aesthetics, the lines and ergonomics are very good. We were told the current range in economy mode is ~60 miles, and in power mode ~30 miles, but they are working on that. The regenerative braking is smoothly linear as you roll off the throttle, and most of the time i didn’t use the physical brakes until we came to an absolute stop as the regen braking slowed the bike way more than normal engine braking does.

If you get a chance, have your motorcycle endorsement, and the tour comes anywhere near you – definitely check it out!

20141011_103208

Windows 10 Technical Preview – nice!

win8logo-11324441

So folks who have known me for a while know I’ve been working with Microsoft operating systems since DOS 3.1, and Windows since Windows/386. Things have come a looooong way since then. I wasn’t a fan of Windows 8, and stuck with Windows 7 until I very recently converted to using a Mac due to that becoming the prevalent machine for web devs.

Credit to Microsoft that the Windows 10 Technical Preview comes in 32- and 64-bit ISOs that drop right into VirtualBox, and they even mention using a VM solution on the preview site so are on board with it. It took a couple passes to get the settings just right, here’s my config if anyone else finds value in it:

  • OSX 10.9.5
  • VirtualBox 4.3.16
  • VM defined as Windows 8.1, 64-bit
    • 2G RAM
    • 2 CPUs
    • 20G Dynamic VDI
    • Enabled 2D GPU

I’m running on a Mac Mini (Late 2012) i7 with 16G, so it’s not a slouch by any means.

The install went very smoothly, but unfortunately the VirtualBox Guest Additions don’t recognize the OS signature so won’t install, but I don’t think I’m going to lose much in testing at this point. For those wondering what the next generation of Windows looks like at this point:

2014-10-02_0154

 

First blush, that annoying home screen is gone, and the start button is back. While not OSX’s Launchpad, it is much more simplified by only showing apps and presenting a Spotlight-like search that finds files, apps, etc on the system to launch. I’m aware the Win7 and Win8 had that search, but it appears to be the focus for the start button in this iteration rather than a shortcut for those who prefer to type what they are looking for. With the Google generation out there, that is probably a good thing. It’s also a more universal and user-friendly interface if Microsoft holds true to porting this OS to phones and tablets as well as any other new platforms they deem necessary.

Another nice new feature is the baked-in desktop manager, which has always been on the wishlist and has always required half-baked implementations (even one by Microsoft as a Power Toy for Windows).

2014-10-02_0205

I haven’t figured out how to move apps between desktops yet, but it’s nice to see this is finally a feature in the core OS.

I’m going to keep poking at it with a stick in my spare time and see what else I uncover. Microsoft warns that this shouldn’t be for the weak of heart, and there’s even a quote on their site that shows a little snarkiness from their marketing team:

We’re not kidding about the expert thing. So if you think BIOS is a new plant-based fuel, Tech Preview may not be right for you.

From what I see so far though, it’s pretty impressive and far more stable than the Windows 8 Preview was, and I look forward to playing with it some more!

 

An Apple doesn’t fall too far…

My new Mac Mini!

So, I have a confession – I’ve been a Linux/Unix/Windows dev for the bulk of my career. However, I’m seeing more and more webdev tools that just don’t play nicely on Windows (even the latest 64-bit offerings) which is an incredible issue when, well, I spend 40+ hours a week doing webdev work.

My last Apple was a ][e waaaaaaay back in the day (and actually was not my first computer – check out the venerable TI-99/4A). This will make only my second Apple desktop I’ve ever worked on, and am retiring the trusty Win7 box this coming weekend.

Why the Mini and not an iMac or MacBook? Quite simply, I have several perfectly good USB-based peripherals that work with OSX as well as two very nice 23″ HD displays I don’t want to give up. I also like the option to easily upgrade the system using off-the-shelf components like memory and drives. And the quad-core i7 is not a slouch by any means…

Nope, not joining the Cult of Jobs, but realizing that the best tool for the job these days is a Mac running OSX.  :)

Recursive field traversal in Drupal

drupal_logo-blue

So say you have to build a custom sitemap for a Drupal 7 site that makes heavy use of Field Collections, and you need to recursively extract every item of a certain field type on a single entity for the sitemap. Oh, and you need to be able to selectively transform some items in the process.

Yep, you guessed it – I’ve run across this one before. We had a series of content types that used heavily-nested field collections and a custom sitemap requirement for the images that good ol’ XML Sitemap just wouldn’t accommodate. So we built one.  :)  Note that this one was geared toward grabbing images and altering the Brightcove module’s thumbnails to conform to our sitemap code’s requirements.

 

Search API + Acquia Solr; A Tale Of Alters

drupal_logo-blue

So, say you have built a great custom search solution for Drupal on top of Solr using Search API. You don’t want to lose it, so you export the entire config using Features, right? No-brainer…

Oh, wait – the client wants to host on Acquia and use their Solr service. Sure, there’s a module for that as well.

But… How do you properly adapt your exported settings to work on Acquia without having to create a whole duplicate server and index config? Enter the Drupal hook system! Search API provides an alter hook for server definitions that allows you to intercept the server configs before they are processed into the Search API subsystem. Here’s a sample of how you can keep your existing settings and simply alter them to point to the correct Solr instance when running on Acquia:

The alter hook replaces the stock Search API Solr settings with the Acquia Search API server settings, examining the AH_SITE_ENVIRONMENT to determine if we’re on an Acquia server and taking advantage of the subscription variable that all Acquia subscription sites have for the subscription key. No muss, no fuss!  Clear caches and/or revert your search Feature, and away you go!

… and the site is rebooted!

I finally came out of denial and acknowledged that I was never going to upgrade the old Drupal 6 site…

I spend 40+ hours a week hammering on large Drupal 7 multisites for work…

Sooooo I figured I’d simplify my life a bit and use WordPress in this incarnation of my blog site. Here’s to hoping this is a relatively painless learning + blogging experience!