Postcards From My Life

Lint I find in my mind's belly-button.
  • EPK
  • Consulting
  • Resume
  • Nerd Herding
  • Talks
  • CWJ 09

Posts Tagged ‘zend framework’

How I got Zend_Tool working on Windows

Tuesday, February 23rd, 2010

Dear Reader,

I love Zend Framework. I love it so much I wrote the very first book about Zend Framework. (Note: It’s no longer the best Zend Framework book, but still, it’s a good one) I’ve written projects using it and I now find myself teaching another class on it. One of the cool things about Zend Framework is it’s cli tool, Zend_Tool. (zf) When zf works, it’s awesome. However, when it breaks, it’s a real pain in the butt. Thanks to buddies like Ralph Schindler though (the author of the tool) when it does break, I can usually get help getting it back up and running.

The latest version of zf that comes with Zend Framework 1.10.x and better is much better than previous version and it shows that Zend (well, at least Ralph) listens when people point out problems and work to solve them.

Even though it’s made great strides, setting up zf is still not seamless. To that end, here is my list of steps needed to setup zf.

My setup

I should note before I start that I am running Windows 7. This means symlinking stuff is right out and we have to resort to physically copying files around. On top of Windows 7, I’m running XAMPP. (anyone know, is that pronounced X-AMP ot ZAMP?) this means that my PHP sits in \xampp\php. I’ve added that directory to my WIndows path so I can execute php from any cmd window. With that understanding, here’s my list.

The steps

  1. Download Zend Framework and unpack it somewhere on your harddrive where you want it to live.
  2. Make sure php.exe is in your PATH and make sure you know where php.exe is.
  3. Find the bin directory in your Zend Framework directory. In it there are 2 files, zf.bat (or zf.sh for Linux) and zf.php. Copy those to the same directory php.exe is in. (Linux users, feel free to just symlink them)
  4. Your Zend Framework directory should contain a library directory, change directory into it.
  5. from the library directory, test your zf to make sure it works, zf show should give you what you need.
  6. Type zf --setup storage-directory On Windows 7, this will create a directory named .zf in c:\Users\<Your Profile Name>
  7. Type zf --setup config-file. On WIndows 7, this will create a file .zf.ini in c:\Users<Your Profile Name>
  8. Using your favorite text editor, open c:\Users\<Your Profile Name>\.zf.ini. There should only be a single line in it that contains the include_path zf will use. Add the full path to your Zend Framework directory here. It should end in “\library\”.

Test it

That’s all there is to getting it setup. (I remember the days when it took twice as long and required cursing just to get it working) To test it out, cd to any directory other than the Zend Framework directory and type zf show version That should give you the current version of the framework you have installed.

Now you are free to start using it to create projects, etc.

Small problem

There is still a problem with defining your own providers. I tried to add my twitter provider (yes, I can use zf to tweet!) and it won’t yet recognize it. I’ve brought this to Ralph’s attention and impressed upon him the importance of being to tweet from zf. I have no doubt that a solution will be forthcoming.
UPDATE
As pointed out in the comments, this has been fixed, just not documented. This page shows how to add your own providers either manually or via a command.

You can either manually add a line to your .zf.ini

basicloader.classes.0 = "My_ClassName"

or you can use zf to update itself

zf enable config.provider class-name

So now I can tweet from zf again. :)

Until next time,
I <3 |<
=C=

[Disclaimer: I use to work at Zend and still have great friends there like the lovely Nili and the walking ray of sunshine that is Andrea. That having been said, it's been a long time since they gave me any money. So the point of this disclaimer is really just so I can mention Nili and Andrea. :) ]

Tags: andrea, cli, nili, PHP, ralph shindler, zend framework, zend_tool
Posted in PHP, Programming | 10 Comments »

 

Update from webcast on Zend_Cache_Frontend_Class

Monday, September 7th, 2009

Dear Reader,

In reading over the chat room log for my recent webcast, Zend Framework: Piece by Piece I noticed a question from my buddy Elazar about Zend_Cache_Frontend_Class. Thinking I had made a mistake, I reviewed the materials and the Zend_Cache_Frontend_Class documentation page so that I could do a quick update. The answer wasn’t nearly as simple as I thought.
(more…)

Tags: cache zend_framework-frontend_class, phar, zend framework
Posted in zend framework | 2 Comments »

 

Zend Framework Piece by Piece

Thursday, September 3rd, 2009

Dear Reader,

Zend Framework is unique in the PHP framework lineup in that it is simple to pull out single pieces and use them independently of the framework itself.

This was the premise of the webcast I presented as part of the summer webcast series, hosted by phparchitect and sponsored by Microsoft.
(more…)

Tags: cache, figlet, JSON, mail, view, zend framework
Posted in zend framework | 10 Comments »

 

Quickie Zend Framework Bootstrap Note

Thursday, August 13th, 2009

Dear Reader,

I’ve been teaching a Zend Framework class this week and my students have been throwing all kinds of questions at me. Most recently, while we were discussing creating a Bootstrap class for an application a question came up about the _init* functions.

The manual states that

$bootstrap->bootstrap();

will fire all of the _init* functions in the bootstrap class. However, the question came up, in what order? Thanks to friends like Rob Allen (author of “Zend Framework in Action“), I was able to give them the answer.

(more…)

Tags: bootstrap, hints, PHP, Programming, tips, zend framework, zend_application
Posted in PHP, Programming, zend framework | 3 Comments »

 

Things I learned about Zend Tool

Tuesday, August 4th, 2009

Dear Reader,

I’m prepping some training on Zend Framework and have been working with Zend Tool a lot. When MWOP first told me about Zend_Tool, I thought cool. and when it hit the incubator, I grabbed it. I followed the two hour install instructions…then did it again, because I missed a step. Finally I had it and zf show version didn’t throw an error. However, everything else did. It pretty much sucked.
(more…)

Tags: PHP, Programming, suckage, zend framework, zend tool
Posted in PHP, Programming, zend framework | 9 Comments »

 

Packaging Zend Framework As A Phar Revisited

Sunday, July 26th, 2009

Dear Reader,

Ok, after I posted my original post on packaging the Zend Framework with Phar and my package.php, I had some additional thoughts. Also, reader John Douglass sent in some code to include. John, I’ve included most of your concepts but I changed up a lot of your code. Nothing personal but since we are using PHP 5.3, we might as well use the GetOpt() function.

(more…)

Tags: phar, PHP, php 5.3, zend framework
Posted in Programming | 3 Comments »

 

Lessons in Phar

Sunday, July 19th, 2009

Dear Reader,

In preparation of an episode of boxlunchtraining.com I have been doing a lot of research into creating and using PHP’s new phar archives. While I’ve not answered all my questions yet, I’ve been able to do most of what I wanted. One of the tasks I wanted to complete was to create a phar archive for Zend Framework. Here is a very quick intro into how I did it. Most of this is just a reminder for me but if you find it useful then I’m glad.

(more…)

Tags: phar, PHP, zend framework
Posted in Programming | 16 Comments »

 

Sun VirtualBox as a virtual development environment for PHP

Wednesday, October 8th, 2008

Dear Reader,

The problem

For the past year I’ve been looking at the way I develop web based projects and how I can make it easier, better, faster, more stable, but most of all, portable. Like many PHP developers out there, I work on multiple projects at the same time. It’s not unusual for me to have three projects under development at any given time with an additional five projects that I’ve abandoned that I’m not yet willing to delete. I’ve developed a way of working with them that works for me. I’ve even written a Zend Framework based cli tool that sets up my work environment the way I like it.

All of that is wonderful if I’m sitting here in my lair connected to my local network. However, if I’m moving around, I have two choices, setup something like Zend Core or XAMPP on my laptop and duplicate my development server. This is the model I’ve used for the past few years but what I end up with is projects on my development server that I wanted on my laptop and visa-versa. The more I thought about it though, the more I realized there had to be a better way. My current setup doesn’t allow me to do things like test PHP 5.3 without setting up a whole new server just for that purpose, or maintain an environment like my production server – it has it’s own little quirks – so that I can work on legacy code.

Here is a short list of my criteria:

  • Must work on my laptop.
  • Must allow me to easily test different environments
  • Must let me work on multiple projects

The solution that doesn’t work

Yesterday I was browsing phpdeveloper.org like all good PHP developers should when I ran across a link to Kevin van Zonneveld’s blog post, How virtualization will improve your code. Reading it over, I begin to think he had hit upon the solution. He was using Sun’s new VirtulBox 2.0 to virtualize the development server. The only problem with Kevin’s solution is that he is running Linux as his primary OS (Host) and runs Linux as the virtualized (Guest) OS. Actually, it’s not a problem for him but it is for me since I use Windows as my desktop environment. I did feel though that he was moving in the right direction.

Installing VirtualBox is very easy and grabbing a copy of Ubuntu Desktop (Don’t use Server, it won’t work According to this thread The problem was a setting in VirtualBox and not Ubuntu itself. It may be safe to use Server if you like.) was actually the longest part of the process. Once downloaded, setting up the virtual server was actually anti-climatic. You just let the wizard get you going and then watch as Ubuntu installs.

One of the great things about VirtualBox is that it has a “shared folders” option. I simply define a directory on my Windows OS (Host), c:\web, as a shared folder and then mount that share inside the Linux OS. Once you you get it working the way you want, you jsut add the mount to your virtual server’s /etc/fstab and never think of it again.

The end result is I can still use Windows/Komodo as my development environment. My virtual server has Apache, PHP and MySQL installed so it can serve up the pages from the same directory. So far, all was going well. Here is where Kevin and I parted company though. Kevin was content to browse the work area using the browsers installed on the virtualized server. This is the easy way to do it because the browser and Apache are on the same virtual machine. I however, wanted to be able to browse the server from my Windows environment so I can test with IE, FF, Safari, etc.

Following the instructions in the Users Guide I setup a “Host Interface”, bridged it to my wi-fi card and setup my virtual server to use the new interface. (It should be noted that I know enough networking to be dangerous so the sentence above actually covered about 3 hours of running down blind alleys) Each time I tried a different combination, my new virtual server fired up just fine but failed to connect to the network.

After a lot of failed tries and a lot of googeling, I found the answer. (Which was, of course, in the manual to begin with) Most wi-fi cards are not capable of promiscuous mode. For bridging to work, Windows has to put the card in promiscuous mode.

Mine card, an Intel® PRO/Wireless 3945ABG, is capable of it but you have to have an admin tool to do it and while I can find the manual for the admin tool, I can’t find anyplace to download the actual tool itself.

Just to confirm that this was actually the problem, I snaked a cable into my lair from my server closet and bridged the host interface and my wired interface. Voila! it worked exactly how I wanted it to. But alas, since the solution is not portable, it won’t fit all my criteria.

Conclusion

Even though VirtualBox won’t meet my need as a development server, it’s still a cool toy to play with. It scratches my Linux itch while letting me keep my Windows desktop. Running it in seamless mode is a little more processor intensive but very cool. It puts the Linux toolbar at the top of the screen and Linux apps open as regular Windows windows.

I’m still in search of the perfect development environment. If I find it, I’ll let you know.

Until next time,
(l)(k)(bunny)
=C=

Tags: Kevin van Zonneveld, php developers, sun, VirtualBox, xampp, zend framework
Posted in PHP, Programming | 25 Comments »

 

I called Zend_Json::encode(), so WTH are all my properties?

Thursday, February 21st, 2008

Dear Reader,

Ok, this one is just stupidity on my part but I’m going to post this here so that hopefully others can learn from my mistake.

The problem is simple, JSON encode a PHP object and send it back to the front end. Sounds simple and the last 100 times I wrote this code it was simple. This time, I was too smart for my own good. Here’s the scenario. The object I’m encoding uses PHPs magic functions __get() and __set. __get() and __set() operate on a protected array named (drum roll please) $_data. (Stop me if you’ve heard this one)

class MyClass
{
    protected $_data;

    public function __construct()
    {
        $this->_data = array('wifesBirthDay' => '',
                             'nuclearLaunchCode' => '');

    } 

    public function __get($index)
    {
        if (isset($this->_data[$index])) {
            return $this->_data[$index];
        }
        return null;
    } 

    public function __set($index, $value)
    {
        if (isset($this->_data[$index])) {
            $this->_data[$index] = $value;
        }
    } 

}

So I instantiate an instance of MyClass and set a few very important properties:

$myObject = new MyClass();

$myObject->wifesBirthday = '5/14';
$myObject->nuclearLaunceCode = 'dontPushThisButton';

Now, var_dump($myObject) returns what you think it would, you can see the protected array and the values.

It was at this point that while I was still able to type coherent code, my brain had checked out for the night. The manual for Zend_Json::encode clearly states:

When encoding PHP objects as JSON, all public properties of that object will be encoded in a JSON object.

Obviously my brain simply chose to ignore this detail.

In my mind, the properties existed…right? Cause I could set them; however, since I’m laying it out here for you, it’s easy to see that since $_data is a protected property, it wasn’t getting passed.

Using FireBug (is there a better FireFox extension? I don’t think so) I could see that my PHP was handing back an empty JSON string to be re-constituted on the client side.

The solution, once I realized what was happening, was quite simple. just create an array of the properties you want to pass back.

$payload = array('wifesBirthday'=>$myObject->wifesBirthDay, 'nuclearLaunchCode'=>$myObject->nuclearLaunchCode);
$output = Zend_Json::encode($payload);

That was my first cut and low and behold it works. However, a better solution came to mind.

class MyClass
{
    protected $_data;

    public function __get($index)
    {
        if (isset($this->_data[$index])) {
            return $this->_data[$index];
        }
        return null;
    } // public function __get($index)

    public function __set($index, $value)
    {
        if (isset($this->_data[$index])) {
            $this->_data[$index] = $value;
            return true;
        }
        return false;
    } // public function __set($index, $value)

    public function getProperties($skip=array())
    {
        $returnValue = array();
        foreach($this->_data as $key=>$value) {
            if (!in_array($key,$skip)) {
                $returnValue[$key]=$value;
            }
        }

        return $returnValue;
    }
}

There, now I can simply write:

$payload = $myObject->getProperties();
$output = Zend_Json::encode($payload);

If I didn’t want to disseminate the nuclear launch codes (I know I’m gonna start getting some weird searches now) I can write:

$payload = $myObject->getProperties(array('nuclearlaunchCode'));
$output = Zend_Json::encode($payload);

So I hope that by embarrassing myself publicly I can help at least one person. (For the record, it really only took me about 2 minutes to trace down the issue.)

Until next time,
(l)(k)(bunny)

=C=

Tags: FireBug, JSON, PHP, zend framework
Posted in JavaScript, PHP, Programming, zend framework | 9 Comments »

 

Book is Available, Support Site is Live

Saturday, January 19th, 2008

Dear Reader,

Well, my first book, php|architect’s Guide to Programming with Zend Framework has officially been released in PDF format. You can order it now or pre-order the dead-tree edition. (Cal is a happy camper)

I would be remiss if I did not say thank you once again to Marco, Elizabeth and Matthew for their help and guidance. Also, a huge thank you to Laura Thomson for writing the forward.

On a related note, the support site for the book, www.zfguide.com is now live. Currently, the only thing there are links to the source code examples but I have plans for posting any errata, discussing different parts of the book and eventually releasing a series of tutorials called “The Missing Chapters”. (because there was a lot I just didn’t get to cover)

Until next time,
(l)(k)(bunny)

Tags: book, elizabeth naramore, laura thomson, marco tabini, matthew weier o'phinney, PHP, zend framework
Posted in Me, PHP, writing | 3 Comments »

 

php|architect’s Guide to Programming the Zend Framework

Friday, January 4th, 2008

programming_with_zend_frameworkDear Reader,

Last week, php|architect announced my book, “php|architect’s Guide to Programming the Zend Framework”. Today I posted the announcement over on DevZone. I’ll admit that I was very nervous posting the announcement on DevZone because I’m not keen on using DevZone for self-promotion. However, in the end, it came down to the fact that I announce other books so I needed to announce this one.

Anyhow, for the both of you who read this, I have a new PHP book out titled “php|architect’s Guide to Programming the Zend Framework”. There’s been a link to it in my sidebar since it was announced but I thought that since I announced it on DevZone, I would post about it here as well.

Until Next time,
(l)(k)(bunny)
=C=

Tags: Cal Evans, devzone, PHP, php|arch, zend, zend framework
Posted in Programming | 8 Comments »

 
  • Team Based PHP Training

  • Sponsors and Ads

  • Conferences I’m Attending

  • About Me

    cal_evansThis is my blog. Sometimes it's my deep thoughts, sometimes it's a journal of things I've learned. Every now and then it's my box of shattered dreams. Most of the time though, it's just the place I like to write. Sit with me as I show you some postcards from my life. While you are here, do me a favor and leave a comment.

    If you are looking for my contact information, bio, picture, ASL, check out my EPK.

    My name is Cal Evans and this is my blog.



    Follow me on FriendFeed!

    View Cal Evans's profile on LinkedIn

  • My First Book

  • Support PHPWomen


    US Shop | European Shop

  • What I'm Doing...

    • Going to CodeStock? Vote for my talk http://bit.ly/aZgFiN (Please?) 1 hr ago
    • ok, podcast edited. (Left in the Ums for the eventual drinking game) Now for lunch and then I've actually got real work to do. :) 3 hrs ago
    • RT @derickr: New blog post: "Available for PHP Extension Writing" — http://derickrethans.nl/available-for-php-extension-writing.html 3 hrs ago
    • More updates...

  • Tags

    API article Cal Evans codeworks conference cw09 developers devzone elizabeth naramore Entrepreneurship Exim flex fun IBuildings iPod Kathy Evans linkedin Mac Management Marketing microsoft MySQL Nashville phar PHP phparchitect php developers podcampnashville podcast podcasting poem Programming Quickies respect RSS Silly-Con Valley sixty second tech software development terry chay twitter upgrade video wordpress zend zend framework

  • RSS PHP Podcasts

    • Writing Composite Zend_Form Elements
    • Preparing Custom Elements for Zend Validators
    • webcast: Introduction to Doctrine 2
    • 8 Reasons Every PHP Developer Should Love JavaScript
    • oddWeek Episode #4
    • Creating Custom Zend_Form Decorators
    • Habits of Highly Scalable Web Applications
    • PHPSPCast #6 – Ao vivo da Campus Party (Q&A)
    • php|architect podcast: oddWeek #003
    • Podcast #2010-02: Stalker Edition

  • XBox Gamer Card

  • Me

    • Best web design company
    • Cal Evans Dot Com
    • Cyrano’s Apprentice
    • Evans Internet Construction Company
    • My Life as a Child
    • PHP Podcasts
    • Sixty Second Tech

  • RSS My Blog at php|arch

    • An error has occurred; the feed is probably down. Try again later.

  • Flickr Recent Photos

    Blue Parabola Southern Office-Rear Annex is closed for snowSnow Heart@dzuelke getting ready to give his talk@fabpot talking about Dependancy Injection@derickr giving the opening keynotePeople meeting other peoplePHP Benelux Goody Bag ContentsCheck InDSCN2280The main room

  • Categories

    • Apache
    • BlogBling
    • Blogging
    • codeworks
    • Entertainment
    • Entrepreneurship
    • Flex
    • Humor
    • JavaScript
    • Long Form
    • Management
    • Marketing
    • Me
    • PHP
    • podcasting
    • Programming
    • SQL
    • Technology
    • Web 2.0
    • wordpress
    • WordPress Plugins
    • writing
    • zend framework

  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org


Postcards From My Life is proudly powered by WordPress
Entries (RSS) and Comments (RSS).