Getting Started

Note: This is just a tutorial, PHPDevShell offers advanced methods while coding. To keep this tutorial simple we used standard PHP code. In this tutorial, we'll use the folder phpdev as the folder where your installation of PHPDevShell resides (if you have not installed yet, follow this link). Change it to fit your actual folder name.

Starting with a new framework is always both a thrill and daunting task. You might feel what you have in front of you is interesting, but how can you get started with the most basics and work with it in its simplest form?

The getting started guide only focuses to get you started on what you are familiar with. For this tutorial we don't want to confuse you with new methods and methodologies, we just want to get you started using "good ol' PHP" for now :). We will guide you and give you a glimpse of why PHPDevShell is ready to get you going in 5 Minutes!

Screenshot_2.png

To follow this tutorial, you'll need:

  • a working installation of PHPDevShell (I'll assume it's accessible at http://localhost/phpdev/)
  • an administrator account (a registration on this installation allowing you to manage plugins)
  • a text editor or IDE to code in (we recommend free NetBeans or free Eclipse),
  • you must also have access to create folders upload files to your installation.

Now lets pick a name for your plugin. In PHPDevShell, every script belongs to a plugin. This allows you to stay consistent within a structure and have a whole site inside a single plugin folder. Let's say you name your plugin "tutorial" (all lowercase). Create a folder with this name inside the "/phpdev/plugins/" folder, e.g. "/phpdev/plugins/tutorial"

Hello world

Of course our first script will be the classic (yet fancier) hello world application, using only code you are familiar with.

Once you have created the tutorial folder in "phpdev/plugins/", you will be placing your new script (lets call it first.php for now) "first.php" inside it. Open/create your first.php script with your favorite PHP editor and start writing code, lets do the promised hello world:

<?php
	// Hello world heading.
	echo "

Hello, world!

"; // But don't feel limited. You have access to absolutely all standard PHP functions, even queries: $query = mysql_query('SELECT * FROM pds_core_users WHERE user_id = 1'); // Or use object queries if Models are not going to be used. $query = $db->newQuery('SELECT * FROM pds_core_users WHERE user_id = 1'); // You can build HTML right here. $html = "

Some HTML

"; echo $html; ?>
Every execution point in PHPDevShell is connected from the menu system as a node. The menu system has node types, this can be seen as an execution point for simple scripts, plugins, websites, widgets, ajax etc. For instance a widget node type can be called from inside a controller node type. This means that when this controller node type is access, the widget inside that node will also be loaded if the widgets node permission allows it.

Adding a menu to open your script in your Browser

The most common way of executing a script is to create a menu item. Creating a menu in PHPDevShell makes an item appears in the dashboard which when clicked will run your script. Go to System Management -> Menu Admin -> New Menu -> Fill the fields in as:

Plugin Item: Standard Plugin (leave rest of left column blank).

Name: The display name visible to the user ; let's try "Hello, World!" (note that this name can be different based on the user's language)

Alias: an alternate name, which can be used from the code to refer to the menu whatever the user's language ; let's try "hello-world"

Plugin Name/Folder: the name of the folder our script reside in; we chose "tutorial" earlier

URL or path: this will tell the engine where exactly to find our script file ; it's "first.php"

Leave the rest to their default values and click "Save". Then click on "Dashboard" in the upper menu: our new menu item "Hello, World!" should appear.

Screenshot-2_0.png

First run

OK we're ready! click on the menu icon "Hello, World!" and you should see your nice greeting. Basically any PHP script can be run that way; we call this "legacy mode" because it's way scripts where written before version 3.0.

But anyone can see my script :(

Ah, so you want to quickly protect your secretive Hello World with some magic using the Access Control? That is not a problem, simply add this line at the top of your script:

	// Stop people from seeing my highly secretive menu.
	(is_object($this->security)) ? $this->security->securityIni() : exit('Access Denied!');

Now remember to give your menu item the right permissions using by going to System Management->Policy Admin->Access Control

Sample Plugin

PHPDevShell is packaged with a sample plugin called ExamplePlugin, be sure to have a look at it in order to get started as quickly as possible with more advanced coding techniques.

PHPDevShell © 2010 - All rights reserved.