Netbeans and Zend Framework 2 configuration - zh.sh file - php

I am new to PHP and Zend Framework 2.
I am currently going through the ZF2 tutorial. I've run the commands:
php composer.phar self-update
php composer.phar install
Then opened up the latest Netbeans version. However, when asked for the zh.sh file, I couldn't find it anywhere in the zf2-tutorial folder. Is this file something that we need to create or is it expected to exist by default in the ZF2?
It'd be great if someone could point me to the right direction.

As other have hinted, NetBeans has not caught up to ZF2 yet (ZF has only been out for a handful of weeks).
As of right now, ZF2 has no command-line tooling (ie: zf.sh). Instead, you're encouraged to use the Skeleton Application to get things started.
While NetBeans doesn't have any specific ZF2 support, it's still a great IDE to use while developing ZF2 projects.
Just skip the ZF-specific stuff. Grab the Skeleton App, and create a new NetBeans project ("from existing sources"), and start hacking.
In all honesty, I can't remember ever using any of the ZF-specific stuff in netbeans. The framework is just a bunch of PHP files, and NetBeans works well without any framework-specific knowledge.

I don't know the content of zf.sh, but I was using this zf.bat in windows as it should be zf.sh in linux so's. This way I got from netbeans my zend core in the creation project phase ( with no errors):
git clone git://github.com/zendframework/ZendSkeletonApplication.git
cd ZendSkeletonApplication
php composer.phar self-update
php composer.phar install
With Zend included in php.ini, and COMPOSER_PROCESS_TIMEOUT=5000 set in the same file (also set max_execution_time=5000). This is because it didn't work for me to put it in command line orders.

Related

How can I specify the symfony version of my project in netbeans?

I am trying to create a symfony2 project, with the symfony2.8 version. However whenever I create a symfony project in netbeans I cannot find where to specify the version of symfony and it always creates a symfony3 project. Is there any way to tell netbeans to use the symfony2 version instead of 3?
I'd save yourself the headache and time of trying to figure that out, and instead use the Symfony recommended way.
php -r "readfile('https://symfony.com/installer');" > symfony
# for example, if WAMP is used ...
">c:\> move symfony c:\wamp\bin\php
# ... then, execute the command as:
">c:\> symfony
# moving it to your projects folder ...
">c:\> move symfony c:\projects
# ... then, execute the command as
">c:\> cd projects
">c:\projects\> php symfony
https://symfony.com/doc/current/setup.html
Net-beans will still recognise your project as a Symfony project along with all the added benefits, but also with the ease of setting up new Symfony projects with one command from the CLI.
If you really want to stick to the Net-beans way, simply allow Net-beans to install it, however it chooses. Once it's installed change the version number within the composer.json file. The biggest issue you'll have for this is you'll have to check all your version numbers are compatible.

Zend Framework 2.5 installation process + Nginx + Ubuntu 14.04

I'm trying to install Zend on my ubuntu 14.04 + Nginx.
1) I have downloaded zend via composer
composer require zendframework/zendframework 2.5.0
2) Tell php location of zendframework via include_path. Something like that
include_path = ".:/usr/share/php:/home/dmitriy/zend/vendor/zendframework"
Folder looks like:
Zendframework folder
At this step, I thought that everything is almost done, and i need to download skeleton application to launch index.php.
3) I downloaded zip form Zend Github Repository. Extracted it.
Created nginx entry point to /public/index.php.
What I get at finish:
Page w/o images,css, etc.
Console:Console with wrong paths
Links are not reachable...
Can someone tell me:
1) Is step No:2 required?
2) Why links are broken?
3) Zend(1.11) library have another structure, maybe it is problem here and I have download wrong files?
Or give me links for ubuntu+nginx guide, i could not find.
Thank you.
You seem to be trying to install ZF2 rather than ZF1, so you can drop all the old bad practices such as modifying the include path to include a library.
Please have a look at the official tutorials to get started: https://docs.zendframework.com/tutorials/
Short version: you can download a "skeleton" rather than the librar(y|ies). A skeleton is a fully configured Zend Framework MVC project, you can then tweak it to suit your needs.
On another note, most php projects do not use the include path to autoload libraries for a few years now, and use Composer and the PSR-0 and PSR-4 recommandations. As you only seem to get started, I'd recommand you read a bit on PSRs, and then follow a ZF3 or Zend Expressive tutorial to get started, and not bother learning a legacy framework (even though ZF2 and ZF3 are really similar).

How to Deploy a Cake PHP App

I wonder if someone can help me. I've been handed in a Cake PHP app that I need to 1) add minor changes 2) deploy. I've never really worked with Cake before and was wondering whether do I need to anything in order for it to work?
For instance, With a Node app, you need to install modules npm install. With a Rails app you'll likely need to install the gems bundle install.
Is there something similar with Cake? I've set the localhost server, but when I try to access the url I get all sort of errors. Some I've fixed (missing environment settings which I just override the Redis host and port). The latest one is:
{
"exception":{
"class":"MissingControllerException",
"code":404,
"message":"Controller class Controller could not be found.",
"file":"\/Library\/WebServer\/Documents\/php\/oompbe\/vendors\/cakephp\/lib\/Cake\/Routing\/Dispatcher.php",
"line":154,
"trace":[
"#0 \.../app\/webroot\/index.php(109): Dispatcher->dispatch(Object(CakeRequest), Object(CakeResponse))",
"#1 {main}"
]
}
}
PS: What's up with all the crazy \/\/?
PPS: Can I find out the version Cake I'm running?
CakePHP is just php. As most properly done php apps these days it comes with composer. I recommend you to read at least the basics of it's manual. Composer is an awesome tool.
git clone <repo>
cd <reponame>
composer install
If you start a new Cake application the official documentation tells you how to this as well:
composer create-project --prefer-dist cakephp/app [app_name]
If you want to automate things further composer provides you callback scripts. They'll allow you to automate tasks, basically trigger commands, after different actions. This is pretty useful to build assets after a composer update for example. I recommend you to not put lots of commands into that section but instead have dedicated script files you trigger by the callbacks.
Can I find out the version Cake I'm running?
If installed via composer it is usually in vendor/cakephp/cakephp/version.txt. Check the content of that file.

How do I successfully create a project with Zend Framework and PHPUnit?

Let me just start by saying that I've posted this to multiple forums and even tried to get help on the ZF IRC channel. I've been Googling for a straight week and still no results. I've read a lot of Q's and A's on this site in the past, so I figured I'd make an account and try asking you.
(Yes, I've searched previously asked questions, but none of the answers helped me.)
I'm trying to learn how to use Zend Framework for a new project that I've joined. For compatibility reasons they are using Zend 1 (and not the newer Zend 2). I have found and followed a number of online and physical book tutorials but I've the same results over and over again.
So here goes (this are the instructions that all the tutorials give). I went to framework.zend.com and downloaded the full version of ZF 1.12.
I unzipped the contents
I moved the library folder to a safe directory where it won't be modified
I moved the contents of the bin folder to same directory as my PHP executable
I changed the include_path in my php.ini file to include the library directory
I updated my Windows PATH variable to make sure it included the path to the PHP executable
I ran
zf --help
This command worked as intended. I also successfully ran zf show version (Zend Framework Version 1.12.7).
I ran the command
zf create project myproject
Upon doing this, I receiving the following error message:
Fatal error: Class 'PHPUnit_Framework_TestCase' not found in D:\Zend\library\Zend\Test\PHPUnit\ControllerTestCase.php on line 48
That particular line in question is a class declaration that extends PHPUnit_Framework_TestCase. I don't know where PHPUnit_Framework_TestCase is defined. It is not in any of the files or directories that came in the single ZIP file that I downloaded from Zend. I even ran grep on all files and folders searching for the string "class PHPUnit_Framework_TestCase" but it printed no results.
Some have suggested that I don't have PHPUnit installed (which is obvious to me now). The part that bugs me is that absolutely none of the tutorials that I read mention anything about installing PHPUnit before hand or how to install it or what dependencies Zend has on it. Many of these were beginner tutorials that assumed you only had a basic knowledge of PHP, and it's pretty shocking to me that none even mentioned PHPUnit. If PHPUnit was that important I would think that the file I downloaded from Zend would have included it. I guess not.
So I went online again and got the PHAR file for PHPUnit, but now what? I tried putting it in multiple different directories but I still get the same error. Am I not supposed to use a PHAR file? Should I be using the actual files instead?
What do I have to do to get ZF to recognize PHPUnit, resolve this error and create my first ZF project?
Additional Info:
Windows 7, XAMPP Server (running on localhost), PHP 5.5.6
Assuming you have PHPUnit installed and it is on your include path (Bearing in mind that ZF1 only officially supports PHPUnit 3.4.x and definitely doesn't support anything above PHPUnit 3.5.x, so if you're using XAMPP you may have to downgrade PHPUnit as described here). The problem is most probably due to this commit, where the require calls for PHPUnit were stripped out in favour of using an autoloader. The ZF tool over CLI doesn't set up an autoloader though, so PHPUnit is not found because it is simply not required! To fix you can return these lines to the start of Zend/Test/PHPUnit/ControllerTestCase.php
/** #see PHPUnit_Runner_Version */
require_once 'PHPUnit/Runner/Version.php';
/**
* Depending on version, include the proper PHPUnit support
* #see PHPUnit_Autoload
*/
require_once (version_compare(PHPUnit_Runner_Version::id(), '3.5.0', '>=')) ? 'PHPUnit/Autoload.php' : 'PHPUnit/Framework.php';
It's worth noting that even with the error you mention, ZF tool should still work correctly when setting up a project, it just won't produce unit test actions (you'll have to make them yourself). If you don't want to downgrade your XAMPP PHPUnit version you should be able to add the correct version locally to your project using composer as described here.
Update Jan 2015:
Downgrading PHPUnit for XAMPP is no longer necessary as ZF1 has supported at least version 4.1 of PHPUnit since 1.12.7 (I've not tested above 4.1). This is helpful as PHPUnit has completely removed their deprecated Pear repository as of December 2014, which means you can't download versions older than 3.7 anymore anyway! (Currently XAMPP ships with PHPUnit 3.6). These days though it's probably worth chucking XAMPP for Vagrant and globally installing PHPUnit 4.1 via Composer during Vagrant provisioning.
I recommend using Composer to load both ZF and PHPUnit. Then make sure to include the Composer autoload.php file as your/in your phpunit boostrap file.
I had the same problem when I set up my laptop as a second development machine and downloaded the newest version of Zend Framework 1 (1.12.9). Whenever I tried to create a new action in a controller, I got the same error. Yet on my main computer, it worked fine.
I realized it was because the version of ZF1 I had in my php includes path was actually 1.11.11. So I went and got 1.11.14 from the ZF archives page, put it in the includes directory, and it worked fine.
Not entirely sure if this is the best way to make it work, since it is an older version, but at least it does work. And until someone actually comes on here and offers a better solution, that's what I intend to stick with.
You can create or edit a .zf.ini file in your home directory (~/.zf.ini or C:\Users\YOUR_ACCOUNT\.zf.ini on Windows)
php.include_path = "PATH_TO_THE_LIBRARY_FOLDERS_CONTAINING_ZEND_AND_PHPUnit"
basicloader.classes.0 = "PHPUnit_Framework_SelfDescribing"
basicloader.classes.1 = "PHPUnit_Framework_Test"
basicloader.classes.2 = "PHPUnit_Framework_Assert"
basicloader.classes.3 = "PHPUnit_Framework_TestCase"
If you are using Netbeans on Windows it could looks like this (you can put several library folder, just separate them with a semicolon ;) :
php.include_path = "C:\Users\romain\dev\ZendFramework-1.12.17\library;C:\Program Files\NetBeans 8.1\php\zend;C:\xampp\php\pear"
basicloader.classes.0 = "NetBeansCommandsProvider"
basicloader.classes.1 = "PHPUnit_Framework_SelfDescribing"
basicloader.classes.2 = "PHPUnit_Framework_Test"
basicloader.classes.3 = "PHPUnit_Framework_Assert"
basicloader.classes.4 = "PHPUnit_Framework_TestCase"

Can projects using PHP framework operate standalone?

I am interested in the PHP framework, especially by symfony and ZendFramework, but I am not sure of one thing: I saw the need to type command lines to create a project with these frameworks. Ok, but once the project is finished, is it possible to move files to another server without installing anything (except for Apache)?
Thank you in advance
Ps: No report, but do StackOverflow uses a framework?
It is absolutely possible to run a symfony or zend framework application without installing the framework on the server. Symfony has a special mechanism to pack everything into one folder. If you use zend framework you basically have to copy the "Zend" folder to your "lib" directory and you are ready to go.
As far as I know, StackOverflow is build on ASP.net and C# running on several windows servers.
Firstof, most of those commands are needed for development only. But also you do not have to have the commands in your global path, it's also possible to execute the scripts directly.
In case of symfony that would be something like
./symfony-framework/data/bin/symfony
if you installed symfony to symfony-framework.
I believe stackoverflow is based on .NET MVC or plain ASP .NET - http://meta.stackoverflow.com will give you that answer
With Zend Framework, it is possible. The Zend_Tool part, which sets up the basics of your project is just addition. You can, but you don't have to use it at all. You can just write the project from scratch yourself, just stick to the standard project architecture.
Anyway, once the project is ready, it does not need any command line setup, other than mayby setting correct file system permission if your project needs to write some files.
I can't say about symphony, but I assume it also can be just copied to the target server.
I don't know, how about ZF, but project made with Symfony can be easily moved to another server just by copying files. However it will be difficult to maintain your project without commands. Also you have to copy all Symfony's core files to your server, but it will be better to install Symfony there before.
About Symfony:
Usually, you develop locally on your dev environment (using Wampserver or MAMP for example). You will require access to the command line to run symfony commands, specially for complex tasks like ORM tasks. So you have to install symfony on that environment.
According to the official doc the recommended installation method is through SVN (either the trunk or a tag) inside your project folder.
When you'll push the files from your dev environment to another (using project:deploy if you can), all the required files will be pushed.
So there is no need to install (in the sense of "run" or "execute") anything on the live environment server. The only "installation" method that requires an access to the command line is the PEAR install method, which is not recommended.
The only problem that I had when I deployed an application was a user permission problem on the cache folder, but that's easy to fix by changing the folder permission.

Categories