.htaccess

RSS
Posts: 7

PhpEd Nusphere debugger gives “web server failed” debugging Zend framework project: dbg-wizard not found

To debug a Zend framework project set to run on a virtual host, use these settings:

  • Web Server (Apache or another) used for development is located on this machine
  • Document root: C:\zs\quickstart\public (i.e., the PUBLIC directory of your project)
  • URL: http://quickstart.local/ (i.e, the virtual URL of your project)
  • Project root directory: C:\zs\quickstart\public (i.e., the PUBLIC directory of your project)

A heavily corrected Windows XP XAMPP Zend Framework Quickstart Tutorial Revision

http://framework.zend.com/manual/en/learning.quickstart.intro.html

With many thanks to commenter alstanto on: 2010-04-07 22:04:18

Download Zend Framework 1.10.5 from:
http://downloads.zend.com/framework/1.10.5/ZendFramework-1.10.5.zip

Pre-Tutorial

  • Extract to c:\ZendFramework-1.10.5
  • Rename directory to c:\Zend
  • Add to Environment Path:
    ;C:\Zend\bin;C:\Zend\library;C:\xampp\php
  • Uncomment C:\xampp\apache\conf\httpd.conf
    Include conf/extra/httpd-vhosts.conf
  • In C:\xampp\apache\conf\extra\httpd-vhosts.conf add:
    <VirtualHost *:80>
    DocumentRoot "c:\zs\quickstart\public"
    ServerName quickstart.local
    SetEnv APPLICATION_ENV "development"
    <Directory c:\zs\quickstart\public>
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
    </Directory>
    </VirtualHost>
    <VirtualHost *:80>
    DocumentRoot C:\xampp\htdocs
    ServerName localhost
    </VirtualHost>
    
  • In C:\WINDOWS\system32\drivers\etc\hosts add:
  • 127.0.0.1 quickstart.local

    This means your tutorial files are accessed via http://quickstart.local

  • Uncomment C:\xampp\apache\conf\httpd.conf
  • LoadModule rewrite_module modules/mod_rewrite.so
    
  • In C:\xampp\php\php.ini add ;c:\zend\library;  to include_path:
    include_path = ".;C:\xampp\php\pear\;c:\Zend\library"
  • In C:\xampp\php\php.ini, uncomment
    extension=php_pdo.dll
    extension=php_pdo_sqlite.dll

Reboot

START tutorial

http://framework.zend.com/manual/en/learning.quickstart.create-project.html

  • Run zf command line tool:
    start, run, cmd
    cd \
    mkdir zs
    cd zs
    zf create project quickstart
  • This is not in the tutorial: add a rewrite rule to public/.htaccess so that the file looks as follows:
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} -s [OR]
    RewriteCond %{REQUEST_FILENAME} -l [OR]
    RewriteCond %{REQUEST_FILENAME} -d
    RewriteRule ^.*$ - [NC,L]
    RewriteRule ^.*$ index.php [NC,L]
    RewriteRule !\.(js|ico|txt|gif|jpg|png|css)$ index.php
  • View welcome page
    http://quickstart.local

CONTINUE tutorial

http://framework.zend.com/manual/en/learning.quickstart.create-layout.html

  • Return to the cmd line at C:\zs\quickstart
    zf enable layout
  • Edit C:\zs\quickstart\application\BootStrap.php. Add this method to the Bootstrap class:
    protected function _initDoctype()
    {
    $this->bootstrap('view');
    $view = $this->getResource('view');
    $view->doctype('XHTML1_STRICT');
    }
    
  • Add line to C:\zs\quickstart\application\configs\application.ini, production section:
    resources.view[] =
  • Replace the contents of C:\zs\quickstart\application\layouts\scripts\layout.phtml with:
    <!-- application/layouts/scripts/layout.phtml -->
    <?php echo $this->doctype() ?>
    <html xmlns="http://www.worg/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf- />
    <title>Zend Framework Quickstart Application</title>
    <?php echo $this->headLink()->appendStylesheet('/css/global.css') ?>
    </head>
    <body>
    <div id="header" style="background-color: #EEEEEE; height: x;">
    <div id="header-logo" style="float: left">
    <b>ZF Quickstart Application</b>
    </div>
    <div id="header-navigation" style="float: right">
    <a href="<?php echo $this->url(
    array('controller'=>'guestbook'),
    'default',
    true) ?>">Guestbook</a>
    </div>
    </div>
    <?php echo $this->layout()->content ?>
    </body>
    </html>
    
  • View new layout, note guestbook is not yet hooked up:
    http://quickstart.local

Continue tutorial

http://framework.zend.com/manual/en/learning.quickstart.create-model.html

  • Tutorial commands will not work in Windows. Tutorial asks you to run in cmd c:\zs\quickstart:
    zf configure db-adapter "adapter=PDO_SQLITE&dbname=APPLICATION_PATH '/../data/db/guestbook.db'" production

    The tutorial would also have you put all three databases in the [production] section. Instead run these commands:

    zf configure db-adapter "adapter=PDO_SQLITE&dbname=APPLICATION_PATH \"/../data/db/guestbook.db\"" production
    zf configure db-adapter "adapter=PDO_SQLITE&dbname=APPLICATION_PATH \"/../data/db/guestbook-testing.db\"" testing
    zf configure db-adapter "adapter=PDO_SQLITE&dbname=APPLICATION_PATH \"/../data/db/guestbook-dev.db\"" development

This is neither part of the tutorial NOR the project.
If you want to use MySql instead of Sqlite:

  • In c:/xampp/php/php.ini, uncomment
    extension=php_pdo_mysql.dll
  • At cmd c:/zs/quickstart, run command (change to your dbname, host, username, password)
    zf configure db-adapter "adapter=PDO_MYSQL&dbname=mydb&host=localhost&username=root&password production
  • Restart Apache
  • In localhost/phpmyadmin create database mydb
  • Create the db directory in cmd at c:\zs\quickstart (you don’t do this for mysql):
    mkdir data\db
    attrib -R data
    
  • At this point the tutorial would have you create scripts/schema.sqlite.sql and other database files. The tutorial took you through creating data\db, so it should also mention that scripts needs to be created. In cmd at C:\zs\quickstart:
    mkdir scripts
    
  • Create c:/zs/quickstart/scripts/schema.sqlite.sql (for mysql name the file schema.mysql.sql)
    -- scripts/schema.sqlite.sql
    --
    -- You will need load your database schema with this SQL.
    CREATE TABLE guestbook (
    id INTEGER NOT NULL PRIMARY KEY AUTOINCREMENT,
    email VARCHAR(32) NOT NULL DEFAULT 'noemail@test.com',
    comment TEXT NULL,
    created DATETIME NOT NULL
    );
    CREATE INDEX "id" ON "guestbook" ("id");
    
  • Create c:/zs/quickstart/scripts/data.sqlite.sql (for mysql name the file data.mysql.sql)
    -- scripts/data.sqlite.sql
    --
    -- You can begin populating the database with the following SQL statements.
    INSERT INTO guestbook (email, comment, created) VALUES
    ('ralph.schindler@zend.com','Hello! Hope you enjoy this sample zf application!',DATETIME('NOW'));
    INSERT INTO guestbook (email, comment, created) VALUES('foo@bar.com','Baz baz baz, baz baz Baz baz baz - baz baz baz.',DATETIME('NOW'));
    
  • Create scripts/load.sqlite.php (for mysql name the file load.mysql.php and change all script references from sqlite to mysql). The tutorial does not include <?php and ?>. Add these.
    <?php
    // scripts/load.sqlite.php
    /**
    * Script for creating and loading database
    */
    // Initialize the application path and autoloading
    defined('APPLICATION_PATH')
    || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application'));
    set_include_path(implode(PATH_SEPARATOR, array(
    APPLICATION_PATH . '/../library',
    get_include_path(),
    )));
    require_once 'Zend/Loader/Autoloader.php';
    Zend_Loader_Autoloader::getInstance();
    // Define some CLI options
    $getopt = new Zend_Console_Getopt(array(
    'withdata|w' => 'Load database with sample data',
    'env|e-s'    => 'Application environment for which to create database (defaults to development)',
    'help|h'     => 'Help -- usage message',
    ));
    try {
    $getopt->parse();
    } catch (Zend_Console_Getopt_Exception $e) {
    // Bad options passed: report usage
    echo $e->getUsageMessage();
    return false;
    }
    // If help requested, report usage message
    if ($getopt->getOption('h')) {
    echo $getopt->getUsageMessage();
    return true;
    }
    // Initialize values based on presence or absence of CLI options
    $withData = $getopt->getOption('w');
    $env      = $getopt->getOption('e');
    defined('APPLICATION_ENV')
    || define('APPLICATION_ENV', (null === $env) ? 'development' : $env);
    // Initialize Zend_Application
    $application = new Zend_Application(
    APPLICATION_ENV,
    APPLICATION_PATH . '/configs/application.ini'
    );
    // Initialize and retrieve DB resource
    $bootstrap = $application->getBootstrap();
    $bootstrap->bootstrap('db');
    $dbAdapter = $bootstrap->getResource('db');
    // let the user know whats going on (we are actually creating a
    // database here)
    if ('testing' != APPLICATION_ENV) {
    echo 'Writing Database Guestbook in (control-c to cancel): ' . PHP_EOL;
    for ($x = 5; $x > 0; $x--) {
    echo $x . "\r"; sleep(1);
    }
    }
    // Check to see if we have a database file already
    $options = $bootstrap->getOption('resources');
    $dbFile  = $options['db']['params']['dbname'];
    if (file_exists($dbFile)) {
    unlink($dbFile);
    }
    // this block executes the actual statements that were loaded from
    // the schema file.
    try {
    $schemaSql = file_get_contents(dirname(__FILE__) . '/schema.sqlite.sql');
    // use the connection directly to load sql in batches
    $dbAdapter->getConnection()->exec($schemaSql);
    chmod($dbFile, 0666);
    if ('testing' != APPLICATION_ENV) {
    echo PHP_EOL;
    echo 'Database Created';
    echo PHP_EOL;
    }
    if ($withData) {
    $dataSql = file_get_contents(dirname(__FILE__) . '/data.sqlite.sql');
    // use the connection directly to load sql in batches
    $dbAdapter->getConnection()->exec($dataSql);
    if ('testing' != APPLICATION_ENV) {
    echo 'Data Loaded.';
    echo PHP_EOL;
    }
    }
    } catch (Exception $e) {
    echo 'AN ERROR HAS OCCURED:' . PHP_EOL;
    echo $e->getMessage() . PHP_EOL;
    return false;
    }
    // generally speaking, this script will be run from the command line
    return true;
    ?>
    
  • At the cmd c:\zs\quickstart
    php scripts/load.sqlite.php --withdata
  • At the cmd c:\zs\quickstart
    zf create db-table Guestbook guestbook
  • Create application/models/GuestbookMapper.php
    <?php
    // application/models/GuestbookMapper.php
    class Application_Model_GuestbookMapper
    {
    public function save($model);
    public function find($id, $model);
    public function fetchAll();
    }
    ?>
    
  • At the cmd c:\zs\quickstart
    zf create model GuestbookMapper
    
  • Replace contents of application/models/GuestbookMapper.php with:
    // application/models/GuestbookMapper.php
    class Application_Model_GuestbookMapper
    {
    protected $_dbTable;
    public function setDbTable($dbTable)
    {
    if (is_string($dbTable)) {
    $dbTable = new $dbTable();
    }
    if (!$dbTable instanceof Zend_Db_Table_Abstract) {
    throw new Exception('Invalid table data gateway provided');
    }
    $this->_dbTable = $dbTable;
    return $this;
    }
    public function getDbTable()
    {
    if (null === $this->_dbTable) {
    $this->setDbTable('Application_Model_DbTable_Guestbook');
    }
    return $this->_dbTable;
    }
    public function save(Application_Model_Guestbook $guestbook)
    {
    $data = array(
    'email'   => $guestbook->getEmail(),
    'comment' => $guestbook->getComment(),
    'created' => date('Y-m-d H:i:s'),
    );
    if (null === ($id = $guestbook->getId())) {
    unset($data['id']);
    $this->getDbTable()->insert($data);
    } else {
    $this->getDbTable()->update($data, array('id = ?' => $id));
    }
    }
    public function find($id, Application_Model_Guestbook $guestbook)
    {
    $result = $this->getDbTable()->find($id);
    if (0 == count($result)) {
    return;
    }
    $row = $result->current();
    $guestbook->setId($row->id)
    ->setEmail($row->email)
    ->setComment($row->comment)
    ->setCreated($row->created);
    }
    public function fetchAll()
    {
    $resultSet = $this->getDbTable()->fetchAll();
    $entries   = array();
    foreach ($resultSet as $row) {
    $entry = new Application_Model_Guestbook();
    $entry->setId($row->id)
    ->setEmail($row->email)
    ->setComment($row->comment)
    ->setCreated($row->created);
    $entries[] = $entry;
    }
    return $entries;
    }
    }
    
  • At c:\zs\quickstart cmd
    zf create model Guestbook
  • Replace contents of application/models/Guestbook.php with:
    // application/models/Guestbook.php
    class Application_Model_Guestbook
    {
    protected $_comment;
    protected $_created;
    protected $_email;
    protected $_id;
    public function __construct(array $options = null)
    {
    if (is_array($options)) {
    $this->setOptions($options);
    }
    }
    public function __set($name, $value)
    {
    $method = 'set' . $name;
    if (('mapper' == $name) || !method_exists($this, $method)) {
    throw new Exception('Invalid guestbook property');
    }
    $this->$method($value);
    }
    public function __get($name)
    {
    $method = 'get' . $name;
    if (('mapper' == $name) || !method_exists($this, $method)) {
    throw new Exception('Invalid guestbook property');
    }
    return $this->$method();
    }
    public function setOptions(array $options)
    {
    $methods = get_class_methods($this);
    foreach ($options as $key => $value) {
    $method = 'set' . ucfirst($key);
    if (in_array($method, $methods)) {
    $this->$method($value);
    }
    }
    return $this;
    }
    public function setComment($text)
    {
    $this->_comment = (string) $text;
    return $this;
    }
    public function getComment()
    {
    return $this->_comment;
    }
    public function setEmail($email)
    {
    $this->_email = (string) $email;
    return $this;
    }
    public function getEmail()
    {
    return $this->_email;
    }
    public function setCreated($ts)
    {
    $this->_created = $ts;
    return $this;
    }
    public function getCreated()
    {
    return $this->_created;
    }
    public function setId($id)
    {
    $this->_id = (int) $id;
    return $this;
    }
    public function getId()
    {
    return $this->_id;
    }
    }
    
  • At cmd z:\zs\quickstart
    zf create controller Guestbook
  • Add these lines to c:\zs\quickstart\application\controllers\GuestbookController.php init method
    $guestbook = new Application_Model_GuestbookMapper();
    $this->view->entries = $guestbook->fetchAll();
    

    So that GuestbookController.php indexAction now looks like this:

    // application/controllers/GuestbookController.php
    
    public function indexAction()
    {
    $guestbook = new Application_Model_GuestbookMapper();
    $this->view->entries = $guestbook->fetchAll();
    }
    
  • Change out the contents of c:\zs\quickstart\application\views\scripts\guestbook\index.phtml with:
    <!-- application/views/scripts/guestbook/index.phtml -->
    <p><a href="<?php echo $this->url(
    array(
    'controller' => 'guestbook',
    'action'     => 'sign'
    ),
    'default',
    true) ?>">Sign Our Guestbook</a></p>
    Guestbook Entries: <br />
    <dl>
    <?php foreach ($this->entries as $entry): ?>
    <dt><?php echo $this->escape($entry->email) ?></dt>
    <dd><?php echo $this->escape($entry->comment) ?></dd>
    <?php endforeach ?>
    </dl>
    
  • View the guest book
    http://quickstart.local

    Note that the sign guest book is not implemented yet

  • At cmd c:\zs\quickstart
    zf create form Guestbook
  • Replace application/forms/Guestbook.php with:
    (add <?php and ?> which are missing in tutorial)

    <?php
    // application/forms/Guestbook.php
    class Application_Form_Guestbook extends Zend_Form
    {
    public function init()
    {
    // Set the method for the display form to POST
    $this->setMethod('post');
    // Add an email element
    $this->addElement('text', 'email', array(
    'label'      => 'Your email address:',
    'required'   => true,
    'filters'    => array('StringTrim'),
    'validators' => array(
    'EmailAddress',
    )
    ));
    // Add the comment element
    $this->addElement('textarea', 'comment', array(
    'label'      => 'Please Comment:',
    'required'   => true,
    'validators' => array(
    array('validator' => 'StringLength', 'options' => array(0, 20))
    )
    ));
    // Add a captcha
    $this->addElement('captcha', 'captcha', array(
    'label'      => 'Please enter the 5 letters displayed below:',
    'required'   => true,
    'captcha'    => array(
    'captcha' => 'Figlet',
    'wordLen' => 5,
    'timeout' => 300
    )
    ));
    // Add the submit button
    $this->addElement('submit', 'submit', array(
    'ignore'   => true,
    'label'    => 'Sign Guestbook',
    ));
    // And finally add some CSRF protection
    $this->addElement('hash', 'csrf', array(
    'ignore' => true,
    ));
    }
    }
    
    ?>
    
  • In c:\zs\quickstart cmd run
    zf create action sign Guestbook
    
  • Replace application/controllers/GuestbookController.php signAction() with:
    public function signAction()
    {
    $request = $this->getRequest();
    $form    = new Application_Form_Guestbook();
    if ($this->getRequest()->isPost()) {
    if ($form->isValid($request->getPost())) {
    $comment = new Application_Model_Guestbook($form->getValues());
    $mapper  = new Application_Model_GuestbookMapper();
    $mapper->save($comment);
    return $this->_helper->redirector('index');
    }
    }
    $this->view->form = $form;
    }
    
  • Replace application/views/scripts/guestbook/sign.phtml contents with:
    <!-- application/views/scripts/guestbook/sign.phtml -->
    Please use the form below to sign our guestbook!
    <?php
    $this->form->setAction($this->url());
    echo $this->form;
    
  • View and add guestbook entries
    http://quickstart.local
zf configure db-adapter "adapter=PDO_MYSQL&dbname=zipforce&host=localhost&username=root&password production

CONTINUE tutorial

http://framework.zend.com/manual/en/learning.quickstart.create-form.html

Zend xampp Windows .htaccess development error messages

To override the production environment default in Zend framework, add this to .htaccess:

SetEnv APPLICATION_ENV development

“development” enables the application to display debugging errors even when the .ini only has a [production] section.

Programmatically determine Joomla homepage

If both mod_rewrite and 301′s are out in full force the home page is not going to be identifiable by a Server query_string containing “frontpage.” To determine if the current code is on the home page:

$s = filter_var($_REQUEST['QUERY_STRING'], FILTER_SANITIZE_SPECIAL_CHARS);
if (empty($s)) {

//you’re on the home page

}

Page 1 of 212»
2013 © Web Programming Answers