Start Developing

Last updated: Jan 15, 2017

Basic Application

The basic Speedy Application consists of a route (path) that will take user to a particular page, but before the page can be displayed the application may need to process or apply some logic to the end page or maybe authenticate a user so the request is passed on to a controller and then to the view which is returned to the user in the end.

Defining a route

The file containing the application routes is App/Routes.php.
Routes are defined along with their request methods. Let us define a route called hello which can be called using the GET method:
Route::get('/hello','HelloController@sayHello');
The above code states that the request on url /hello can be accepted using the GET method.
Here HelloController is the name of the controller to be called and sayHello is the method in that controller to be invoked.

Creating a controller

Open up your terminal or command window and navigate to your Speedy installation directory and key in the following command:
php creator create:controller HelloController The command above creates a controller named HelloController and places it in the /Controllers directory.
Controllers can also be made manually and then put into the Controllers directory but if you use this approach you will need to put the initial code of the controller yourself or the controller will not work as expected.

Note

Although not required, it is a good practice to append the controller name with the word controller, like HelloController / TestController.

Create a function named sayHello in HelloController and return the view you want the user to see. public function sayHello()
{
    return view('hello',['name'=>"Jhonny"]);
}
The function returns a view named hello and passes a variable named name to it.
The view function accepts the first parameter as the view name (without any file extension) and the second parameter is an array of values we want to pass on to the view to show.

Creating a View

The view is the page that will be shown to the user. It is this page where all the processed data is rendered.
The Views directory holds all the views for the application.

Important

All views should be stored in the /Views Directory and all of them should end with the extension .vu.php . E.g. hello.vu.php

Create a file named hello.vu.php in the /Views directory and place the following content in it: <html>
    <head>
        <title>My First Page</title>
    </head>
    <body>
        <h2> Hello {{name}} </h2>
    </body>
</html>
The view file contains the basic HTML code and a variable declared as {{name}}, this is the variable we passed from our controller and wil be replaced with it.

Run your code

Your code is ready to run.
If you do not have a server software installed, go to your terminal / command window and navigate to the project directory and start the Speedy test server by entering the following command:
php creator run:server Head over to the browser and open up the appropriate link:
If you have a server software installed you should open up your public directory path followed by path to be accessed - /hello for your test page.
If you are using the Speedy test server then head over to http://localhost:9090/hello .

Advanced Actions