How to setup First Application in Zend Framework 2

2019-02-04 09:32发布

问题:

i am creating my first application in zf2. i followed Zend Offical website zf2 Skeleton Application.i have downloaded the skeleton app from github as in in the given link.when i extract it and put that in my folder and run it its showing this Fatal Error

 Fatal error: Uncaught exception 'RuntimeException' with message 'Unable to load ZF2. 
 Run  `php composer.phar install` or define a ZF2_PATH environment variable.' in 
 D:\projects\zf2\zf2_app\init_autoloader.php:50 Stack trace: #0 D:\projects\zf2\zf2_app
 \public\index.php(9): require() #1 {main} thrown in D:\projects\zf2\zf2_app
 \init_autoloader.php on line 50

i dont know How to fix this??

and what about this?

To install Zend Framework 2 into our application we simply type:
  php composer.phar self-update
  php composer.phar install

where to type these commands? Help me with my first ZF2 app

回答1:

You should open a cmd window and change directory to your project. You then need to type the following:

php composer.phar install

This will install all the library dependencies for the Zend Skeleton Application - ZF2 in this case.



回答2:

In addition to Rob Allens answer i have good responses so far from Windows User who have less experience with the command line.

You may find my blog helpful, too: Zend Framework 2 installation on Xampp for Windows



回答3:

You may want to follow the following steps:

  1. Download ZF2 Skeleton Application from Github.

  2. Change directory where you want to install, and unzip the skeleton application.

  3. Change directory to "ZendSkeletonApplication-master", and run the following:

    php composer.phar self-update
    php composer.phar install



回答4:

1.Enable LoadModule rewrite_module modules/mod_rewrite.so from your apache

2.Enable extension=php_openssl.dll from your php.ini

3.Install Composer from http://getcomposer.org/doc/00-intro.md#autoloading. There are instructions for both Linux and windows.

4.Download skeleton project from github.( https://github.com/zendframework/ZendSkeletonApplication and click the “Zip” button) to your htdocs.

5.Go to the directory where you have just downloaded the skeleton project.

6.Run php composer.phar install.This will download all the dependencies.

7.Go to http://framework.zend.com/manual/2.2/en/user-guide/skeleton-application.html and create a virtual host accordingly.

<VirtualHost *:80>
  ServerName zf2-tutorial.localhost
DocumentRoot /path/to/zf2-tutorial/public
SetEnv APPLICATION_ENV "development"
<Directory /path/to/zf2-tutorial/public>
    DirectoryIndex index.php
    AllowOverride All
    Order allow,deny
    Allow from all
</Directory>

8.Go to c:\windows\system32\drivers\etc\hosts (Windows)or /etc/hosts(Linux) and add the following lines: 127.0.0.1 zf2-tutorial.localhost localhost

9.Go to http://zf2-tutorial.localhost/ and you should see the welcome page.



回答5:

its seems like you have not Downloaded the zf2 :) download it from here http://framework.zend.com/downloads/latest#ZF2

extract the framework to vendor/ZF2. and you done :) now browse to your app hope it showing No Exception.



回答6:

How about making it easier @Rob Allen? When answering, so that other reader can save 24 hours to 1 minute !! I tried to make it easier from your answer as below:

1) httpd.conf
<VirtualHost *:80>
 ServerName site
 ServerAlias site
 DocumentRoot /var/www/html/s/public
 <Directory /var/www/html/s/public>
    #AddDefaultCharset utf-8
    DirectoryIndex index.php
    AllowOverride FileInfo
    Order allow,deny
    Allow from all
 </Directory>
</VirtualHost>

2) i did git clone git repo
$ ls
composer.json  composer.lock  composer.phar  config  data  db_bck  init_autoloader.php  LICENSE.txt  module  nbproject  public  README.md  vendor

3) I run and i get same error

4) I did now this

$ php composer.phar install
Loading composer repositories with package information
Installing dependencies from lock file
  - Installing zendframework/zendframework (2.0.6)
    Downloading: 100%         

    Skipped installation of bin/classmap_generator.php for package zendframework/zendframework: name conflicts with an existing file
zendframework/zendframework suggests installing doctrine/common (Doctrine\Common >=2.1 for annotation features)
zendframework/zendframework suggests installing ext-intl (ext/intl for i18n features)
zendframework/zendframework suggests installing pecl-weakref (Implementation of weak references for Zend\Stdlib\CallbackHandler)
zendframework/zendframework suggests installing zendframework/zendpdf (ZendPdf for creating PDF representations of barcodes)
zendframework/zendframework suggests installing zendframework/zendservice-recaptcha (ZendService\ReCaptcha for rendering ReCaptchas in Zend\Captcha and/or Zend\Form)
Generating autoload files


5) It works now


回答7:

As you have already downloaded the GIT file Below commands are for windows :

1) Go to the respective folder 2) run the command -> composer update 3) That should let you install and choose optional modules 4) Finally -> php -S 0.0.0.0:8080 -t .\public .\public\index.php

With this you should be able to access the index page at http://localhost:8080/