Last month, we talked about Zend Server. This month, the other brother Darryl, Zend Studio, is on tap. Let's see what's up about that.
I want to continue my ode to Zend products by taking a look at Zend Studio, the IDE that complements but is separate from Zend Server.
In order to actually create the script that you run in this web server, we used a text editor. Notepad is a text editor, but there are lots of others. Some are sophisticated and can do code completion or code coloration (so you can more readily identify when things are entered properly) and such. A lot of heavy-duty PHP gods and goddesses use text editors, so there's nothing wrong with that.
But, if you're using Zend Server, then using Zend Studio as an IDE (rather than just using a text editor) is pretty natural. It's more sophisticated than any editor could be, and for a lot of people it is the answer. If only we could figure out what the question is. Yeah, that's a joke. Feel free to laugh…or not.
Getting Zend Studio
Zend Studio does not come bundled with Zend Server. You have to download it separately.
Like Server, Zend Studio is free for one year for IBM i users. With that, you get support and new releases, but after the first free year, you need to buy a subscription if you want that to continue. Costs are about a couple of hundred dollars per year, so it could be worse, and there are numerous plans to choose from. Pricing info is here.
You can download Studio from the Zend website and follow the carefully written instructions so that you don't have (too many) problems. It's not that hard. After all, I did it, so how tough can it be? Just go here and select the platform you're downloading to (Mac, Windows, or Linux). Remember, IBM i is not an option here as we are putting this on your PC, whereas Server could go on the PC or the i.
Something to Know About Zend Studio
I tend to get hung up on little things, so this may not be a big deal to anyone else, but it took me a while to get straight with a couple of things, so I want to point them out to you now in case you're like me.
How Zend Studio Works
Zend Studio is meant to run along with a server, probably Zend Server, but it doesn't have to be. You could use it with MAMP, for example.
The point is, Studio does not have a built-in web server, and remember, since PHP is a server-side language, you need a web server to make it work. Studio is primarily an IDE, and the server you're using will be separate from it.
However, it does have the ability, when you write a script, to debug or just run that script in Zend Studio and see what the output is—that is, even though you don't have a web server up and running at the moment. The output doesn't appear on a browser window, but rather on a window within Studio. This allows you to do your development and unit testing just in Studio without bringing a formal server into the picture.
What Zend Studio Looks Like
I have to admit, when I first looked at it, I found Zend Studio confusing. Actually, I still find it confusing at times, but I'm honestly not sure what I would do about it if I were in charge of changing it.
Studio consists of multiple (many) windows that each show a particular type of information. They don't have to all be open at the same time (and aren't), but generally enough are open to make it look busy. And there seems to be a certain tendency to change the names of windows or the spot from which you can access them from release to release.
And that may just be me. Seriously. I don't want to scare you away even before you begin, but at the same time, I don't want you to freak the first time you see it. Word to the wise (or whatever): if Studio looks overwhelming the first time you see it, don't panic. You're not the first person to feel that way, and if you just take a deep breath and focus just on the things I will show you, you'll be able to use it pretty quickly. You can always add in more detail later as you become familiar with it.
At this point, I'm going to assume you have Studio loaded on your PC. Go ahead and click on the icon to start 'er up.
There may be some initial windows that come up. It's been a while since I installed my version, and I don't remember. Nor am I about to do it again just for you. Sheesh. The nerve of some people.
One window you will be faced with asks you to select a workspace. Since Studio is a PC product, it needs a workspace to run in. You may actually have several, so it lets you choose which one you want. A default workspace is created when you do the download, but you can easily create others if you feel so moved. This window allows you to select one or set one as a default so that the window no longer appears.
When the main window opens up, you'll see tabs at the top of each sub-window telling you what each does (Figure 1 below), and most of the windows are capable of showing you multiple things. Exactly what windows you have open will depend on your particular configuration (that is, what you had open the last time you used Studio). Naturally, the entire window can be resized, and each individual sub-window can be sized to make it larger or smaller, but those are the only two options available (larger or smaller). At this point, I would take a minute to look over the sub-windows and the tab names. Remember, just breathe.
Figure 1: This is the initial Zend Studio page.
Creating a PHP Project
How do we enter a PHP script? First, make sure the PHP s-w (sub-window) is showing. If it isn't, go up to the top and look at the icon line.
Figure 2: This ribbon line opens PHP Explorer.
On the right side of this line, you'll see PHP or PHP Explorer (I've seen it both ways). Click on that. If you're using an earlier version (like 12.5), you might have to go up to Windows on the menu line and select Show View or Perspectives to find PHP. Once you find it, click on it.
After a moment, the sub-windows will magically reorder themselves, and one with a PHP Explorer tab will appear. In it will be a list of the projects you have already defined. If you're just starting, then this will be empty.
Figure 3: The PHP Explorer Window shows existing projects.
In Studio, you don't create folders or directories in which to store and organize the scripts you create; you create projects. So the first thing we will do is have you create a project. You can't create even a Hello World script until you create a project. Well, you could (as you can see, I have but that was early on, and I know now that it was wrong), but you shouldn't. Put everything in a project. To create a project, go back up to the menu line, and do this: File > New > Local PHP Project.
As you can see from the New list, you can create a large number of objects in Studio. We'll look at almost none of these, but you can experiment on your own. Anyway, the result will be a pop-up window in which you will define your project.
Figure 4: Create a project window.
All I'm going to do here is type in "TechTip," the name I'm assigning to this project, and I may change the version from PHP 5.6 to PHP 7. Up to you. When I start keying in the Project Name, the Next and Finish buttons will un-gray. When I'm ready to continue, I could hit Next, which would take me to a list of extra PHP and other software libraries that I could attach to this project to make their stuff available for these scripts. I'm not going to do that this time, however, so I just hit Finish.
Note that there are other things I can do here. First, if I have several web servers on my system, I can choose the particular one I want associated with this application. I can also decide if I want the app set up in a Zend Framework format. Finally, I can make it work more closely with Composer. Using Composer to manage library and application dependencies is very common in the PHP world, so working it directly into your application is a big plus.
Anyway, as soon as you hit Finish, Studio will update the PHP Explorer window, and you'll see your new project out there. Exciting. But wait. There's a triangle next to it, the international symbol for "open me up and see what's inside." Inside? We haven't created anything in that project yet. “Just what in the Wide World of Sports is a goin' on here?” If you open it up by clicking on the triangle, you'll see three things inside that project, things that Studio has created for you. And if you then click on the triangle by the Include Path or Language Library entries, you'll see even more stuff.
Take another deep breathe. This is not proof of demonic possession. Just relax and focus on your breathing until it is slow and regular. What happens here is Studio is somewhat framework- oriented, and frameworks like to create things that they think you'll use later. Mostly, just ignore this stuff for now. We may use it later, like in a year or two, but for now just know it's there and you don't need to fuss with it.
The one file that you might use is the index.php. Studio has created this automatically. It's a blank PHP file with the name defaulting to the default name for a web home page. All that's in this file is the starting PHP delimiter <?php. But you could use this to start your script in. In our case, we will go thru the process of creating our own PHP file. And remember, when we say "PHP file," we're not talking about a data file but rather a source file where we'll enter our script.
Creating a PHP File
Let's suppose that we don't want to use the index.php that was created for us but instead want to create our own script file. To do this, go back up to the menu line: File > New > PHP File. Suddenly, a window will appear.
Figure 5: Create a PHP file in a project window.
You can click on the project you want this file to be in and then enter the name you want assigned to this file where it says File Name about halfway down. I'm not covering this now, but the Advanced button opens up fields where you can tie this file to a regular data file in your file system. Once you start keying on this screen, the Next and Finish buttons un-gray. I'm going to use the name File1.php.
The Next button takes you to a list of PHP templates that you can assign to this file. Choosing a particular template will cause some standardized code to be automatically thrown in the file, which saves you coding time. Among the choices are models for controllers, action helpers, HTML front ends, etc.
Hitting Finish just gets you out of there. It creates the file and then opens it in the blank window immediately to the right of the PHP Explorer window you're working on.
Figure 6: PHP Explorer shows the project and PHP file.
As you can see, there's not much in File1.php because we didn't select one of the templates, but that's fine with me. What I want you to do at home is add the following code. Be sure you get all the quotes and double quotes correct.
echo 'I"m a total butt wad.';
Sorry, but I think "Hello World" is so day before last Thursday, and I wanted a shout-out to long-haired Penny and The Big Bang Theory. Save this using File > Save. Don't close it; just save.
Figure 7: See PHP Explorer and the file code when you select a specific file.
Running PHP Script in Studio
Now, to run this in Zend Studio and see if it works, go to the menu line and select Run > Run As > PHP CLI Application.
I haven't had good success with Run > Run, so I suggest using Run As. If there are no options when you click on Run As, click Run Configurations below it and then just press Enter. Then go back to Run As and there should be three options there, one of which is the CLI (Command Line Interface) option.
Now, go to the sub-window along the bottom of the screen and select the Browser Output tab.
Figure 8: See PHP Explorer and File1.php when you enter code.
See, it worked. Now this is just a test. We're not running this in the Zend Server, and in fact you don't even need the Server up to develop and test PHP code.
So, Are We Done?
Fine, we're done. At least, I'll let you go at this point. But there's a lot more to do. This script ran perfectly, which is surprising because I wrote it. That ain't gonna happen twice in a row, cowboy. So stay tuned