Quick start Mysql version

 

http://www.webpixel.gr/blog/zend-quickstart-tutorial

As you might noticed, Magento platform is built on top of Zend Framework. Recently released 1.2 version of Magento eCommerce Platform includes Zend Framework 1.7.2. Zend Framework Quickstart is a good place to start getting an idea about using ZF to build applications. I wrote earlier about installing Magento from svn. The next steps include creating a custom module (todo list, a guestbook something simple for an introduction in creating a custom module for Magento) and connecting Magento with 3rd party applications. I have the following structure on my laptop that I use for development: htdocs is in

C:\web\Apache2.2\htdocs

Zend Framework library:

C:\web\Apache2.2\htdocs\ZendFramework-1.7.2\library

and I’ve set in php.ini:

include_path = ".;c:\php\includes;C:\web\Apache2.2\htdocs\ZendFramework-1.7.2\library"

1. Create a folder and unzip Quickstart sample application in that folder:

C:\web\Apache2.2\htdocs\zfquickstart #in my case

2. Setup application paths Because you will not build a single application with ZF I don’t see a good idea in including ZF within each application (that library folder in sample application folder). I keep it outside in htdocs and I’ve setup in php.ini include_path so I won’t need to override include_path using set_include_path… So, if you want to change include_path in your php.ini you can do that. Or you can change index.php:

view plaincopy to clipboardprint?

  1. #set_include_path(APPLICATION_PATH . ‘/../library’ . PATH_SEPARATOR .get_include_path());
  2. set_include_path(‘C:/web/Apache2.2/htdocs/ZendFramework-1.7.2/library’.PATH_SEPARATOR . get_include_path()); 

So start your browser and go to: http://localhost/zfquickstart/public/ You will see a success message from IndexController:

Hello, from the Zend Framework MVC!
I am the index controllers's view script.

View file is application/scripts/index/index.phtml Another thing that we need to fix is the base url, because css file for example is included as /css/global.css and we are in /zfquickstart/public/ and the correct path should be /zfquickstart/public/css/global.css There are many ways to solve that, using Zend_Router and so on… In bootstrap.php find:

view plaincopy to clipboardprint?

  1. $frontController->setControllerDirectory(APPLICATION_PATH . ‘/controllers’);  
  2. #add this (you can create a piece of code to extract this from url):
  3. $frontController->setBaseUrl(‘/zfquickstart/public’);  
  4. #also find:
  5. $view = Zend_Layout::getMvcInstance()->getView();  
  6. $view->doctype(‘XHTML1_STRICT’);  
  7. #and add this line
  8. $view->baseUrl = Zend_Controller_Front::getInstance()->getBaseUrl(); 

and in layouts/scripts/layout.phtml:

headLink()->appendStylesheet($this->baseUrl.'/css/global.css') ?>

And now you have a nice css added to your layout. Now open public/.htaccess and replace:

RewriteRule ^.*$ /index.php [NC,L]
#with
RewriteRule ^.*$ index.php [NC,L]

3. Setting up database for Zend Framework QuickStart application – MySQL version Create database and grant access:

create database zfquickstart;
grant all on zfquickstart.* to 'zfquickstart'@'localhost' identified by 'zfquickstart';
flush privileges;

schema.mysql.sql:

view plaincopy to clipboardprint?

  1. CREATE TABLE `zfquickstart`.`guestbook`(  
  2. `id` INT (8) UNSIGNED NOT NULL AUTO_INCREMENT,  
  3. `email` VARCHAR (50),  
  4. `comment` TEXT,  
  5. `created` DATETIME,  
  6. PRIMARY KEY(`id`)  
  7. ) TYPE = MyISAM; 

data.mysql.sql

view plaincopy to clipboardprint?

  1. INSERT INTO guestbook (email, comment, created) VALUES
  2. (’email.email@zendfoo.com’, ‘Hello! Hope you enjoy this sample zf application!’, NOW());  
  3. INSERT INTO guestbook (email, comment, created) VALUES
  4. (‘foo@bar.com’, ‘Baz baz baz, baz baz Baz baz baz – baz baz baz.’, NOW()); 

You can run the above sql with phpmyadmin/some mysql gui… or you can create a version for load.mysql.php in scripts folder to load this sql intro database… Now, setting up config. In application/config/app.ini, add this section:

[development]
database.adapter       = "PDO_MYSQL"
database.params.host   = "localhost"
database.params.username   = "zfquickstart"
database.params.password   = "zfquickstart"
database.params.dbname = "zfquickstart"

Note: in bootstrap.php the environment is development:

view plaincopy to clipboardprint?

  1. defined(‘APPLICATION_ENVIRONMENT’)  
  2. or define(‘APPLICATION_ENVIRONMENT’, ‘development’); 

That’s it for now… Next episode: Creating a todo list application with Zend Framework

Advertisements

发表评论

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / 更改 )

Twitter picture

You are commenting using your Twitter account. Log Out / 更改 )

Facebook photo

You are commenting using your Facebook account. Log Out / 更改 )

Google+ photo

You are commenting using your Google+ account. Log Out / 更改 )

Connecting to %s