Introduction to the Zend Framework

“Extending the art & spirit of PHP,  Zend Framework is based on simplicity and object-oriented best practices and … is focused on building more secure, reliable, and modern Web 2.0 applications & web services.”     - framework.zend.com

In this advanced Dreamweaver class, we use the Zend Framework as a library of pre-written PHP that we can easily add to our pages to complete complex tasks such as database updates, email responses and user interactions.     In terms of making PHP development more productive, working with Zend is more code-oriented than using the Dreamweaver built-in Server Behaviors, but in the long-run it is much more simple, straightforward and flexible.

Lesson 7 basically rebuilds the work we did in Lesson 6, using Zend instead of Dreamweaver’s canned PHP/MySQL Server Behaviors.

I suggest you start with this tutorial, as it supercedes several of the steps in the textbook and  sets you up for the real code writing part of the chapter from page 227 on.

Setting Up the Zend Framework

In Lesson 7 of David Powers’ textbook he discusses how to set up the Zend Framework in a development environment where you are using WAMP/MAMP/LAMP – the webserver, PHP processor and MySQL all running on the same localhost as Dreamweaver CS5.   For our class, this is not recommended.   Follow these simple instructions here and disregard the steps on pages 214-218.

  • Install ZendFramework, with it’s entire structure starting with sub-folders bin and library in a folder outside of your local website root folder.  This setup will only be used for Site-Specific Code Hinting.
  • You can do all your development by using the ZendFramework setup on my account on SRJC.  Follow the steps on pages 221-223 to create library.php, but assign this string to your $library variable so that it points to the Zend on my account: /home/WWW_pages/jperetz/advdw/ZendFramework/library

This is how your library.php should look:

 

zend framework library

Once this setup is tested and working, you can set up your site-specific code hints following the steps on pages 215-218, using the local folders that you downloaded and installed as the sources of the code hint configuration, as in the book’s example.

Now you can test the Zend MySQL connection and the Zend code hinting, by following the steps on pages 223-226.    I suggest you skip step 2 and set up a single connection using your admin login.    In steps 3 & 4 on page 225, the SRJC Student accounts don’t seem to support the PDO option, but the mysqli interface seems to work well.

Altering the Users Tables

Alter SQL TableThere are a three additions that need to be made to USERS – two columns and a unique index.   The textbook explains the changes using phpmyadmin, but it should be pretty clear how to do this in MySQL Workbench.   These screenshots show both the changes that you need to make and how the index should look after you create it.    Right click on the table name and choose ALTER TABLE to bring up the table definition.

alter sql table add unique index

 

 

 

 

Updating the User System

Essentially Powers rebuilds the user system from scratch using Zend, from page 227 on.    I suggest you follow these tutorials very carefully, there is alot to learn about PHP and Dreamweaver’s advanced coding features.   From page 227 on, you should be able to follow the textbook very closely if you followed the setup steps above.

16 comments for “Introduction to the Zend Framework

  1. Tomas
    March 23, 2011 at 2:05 pm

    Hi Jay – I set up library.php on my SRJC account as outlined above but I’m not getting -any confirmation that $loader is loading correctly – just getting a blank page.

    http://student.santarosa.edu/~tchadsey/library.php

  2. Mitch
    March 27, 2011 at 8:53 pm

    I too am just getting a blank page…??

  3. Mark Alarie
    March 27, 2011 at 9:28 pm

    I got a blank page at first, but after checking the code many times, I found a couple typos. When corrected, the page displayed.

    For example, on line 11, one that got me was Mysqli, not Mysql
    It seems like everything counts here.
    Mark

    • March 27, 2011 at 10:26 pm

      A blank PHP page almost certainly means that there is a syntax error in your PHP code. Dreamweaver should usually give you a headsup about syntax errors if you have code hinting set up correctly.

  4. Mitch
    March 28, 2011 at 9:59 pm

    Code hinging and info bar show no syntax errors, and I have checked it tons of times now. Im not sure what im missing, maybe a fresh pair of eyes could steer me in the right direction??

    Here is the code as I have it typed:

    ‘localhost’,
    ‘username’ => ‘jperetz_admin’,
    ‘password’ => ‘abcdefg’,
    ‘dbname’ => ‘jperetz’);
    $dbWrite = new Zend_Db_Adapter_Mysqli($write);
    } catch (Exception $e){
    echo $e->getMessage();
    }

    Thanks to anyone who takes the time to look at this!

  5. Mitch
    March 28, 2011 at 10:00 pm

    Oops… here it is->

    ‘localhost’,
    ‘username’ => ‘jperetz_admin’,
    ‘password’ => ‘abcdefg’,
    ‘dbname’ => ‘jperetz’);
    $dbWrite = new Zend_Db_Adapter_Mysqli($write);
    } catch (Exception $e){
    echo $e->getMessage();
    }

  6. Mitch
    March 28, 2011 at 10:01 pm

    nevermind. Something weird with this blog will not display all of the php that you type in this textfield

    • March 28, 2011 at 10:04 pm

      do not use the php tags. or you can try wrapping them in code tags, but safer just to omit the php tags when pasting code into a comment.

      Also, I’m not sure what the issue is? library.php shouldn’t display any output

  7. Deb R
    March 29, 2011 at 1:12 pm

    Found some typos in chapter 7.
    http://foundationphp.com/phpcs5/errata.php

  8. Mark Alarie
    March 30, 2011 at 6:47 am

    Deb,
    Thanks for sharing the typos. It fixed my lost passwords problems!
    Mark

  9. April 7, 2011 at 9:53 am

    Above it says, “Once this setup is tested and working” referring to the library.php. How do we test to see if it is working? Is something suppose to show up on the library.php file when you go to it? Mine, like others is also just blank. I can’t find any errors in the code. Here it is:
    $library = ‘/home/WWW_pages/jperetz/advdw/ZendFramework/library’;
    set_include_path(get_include_path() . PATH_SEPARATOR . $library);
    require_once(‘Zend/Loader/Autoloader.php’);
    try {
    Zend_Loader_Autoloader::getInstance();
    $write = array(‘host’ => ‘localhost’,
    ‘username’ => ‘jperetz_admin’,
    ‘password’ => ‘abcdefg’,
    ‘dbname’=> ‘jperetz’);
    $dbWrite = new Zend_Db_Adapter_Mysqli($write);
    } catch (Exception $e) {
    echo$e->getMessage();
    }

  10. April 7, 2011 at 10:01 am

    In the textbook on page 225 there is some code that you can add to library.php to test a database connection and echo back to the screen. It then explains how to remove this code on page 226.

  11. April 7, 2011 at 10:50 am

    Thanks! It works!

  12. Mark Alarie
    April 10, 2011 at 7:30 pm

    Don’t we need to add our own database info for the $write array in library.php?
    Otherwise, where in the code does it know to use our database rather than Jay’s?

    anyway that works for me
    (didn’t work with Jay’s info as shown above, got blank screen)
    Mark

Comments are closed.