Contacts Manager Tutorial
This tutorial is meant to show how quick and easy it is to get a basic Adroit application up and running, with some basic CRUD functionality. To cut redundant developement tasks down, Adroit provides a set of "build" scripts located in the "scripts" directory included with the download. This tutorial will make use of those scripts, as should anyone when creating a new application.
Lets begin! If you haven't downloaded Adroit already, do so now, and extract it to the desired location for your applications workspace.
-
Open up a terminal/command line window, and navigate to your applications directory, and the "scripts" sub-directory inside of it. Run the following command:
>php buildappYour application directory should now look as follows:
- You may need to edit your "webroot/.htaccess" file (line 3) and your "adroit.conf.php" file (line 7) to adjust your applications webroot in location to your webservers root.
-
Check your application in the browser, it should be as follows:
- We need a database for our Contacts Manager, so we'll set one up called "contacts" on our MySQL server, and enter the database configuration settings in "adroit.conf.php" on lines 13-18. Make sure and un-comment out those lines as well.
-
Back in your terminal windows, run the following command to build a Model to represent a "contact":
>php buildmodel Contact
-
This should have created the following file: "app/model/Contact.model.php". Open this up, and insert the desired fields you want to store for your Contact object as public properties. We added the following properties to our model:
public $name; public $phone, $email; public $street, $city, $state, $zip;
-
We now need a table in our database to store our "Contact" information. Run the following build command from the command line:
>php buildtable ContactThis should create a "contact" table in your database with columns matching up to the attributes you added to your Contact model. You'll notice there is an additional "id" and "created" column in the table, which are inherited from BaseModel. If at anytime you add new attributes to your Model, you can run this script again and new columns will be inserted into your table.
-
To create a generic CRUD controller and set of views for our Contact model, run the following command:
>php buildscaffolding ContactThis will create a controller, "app/controller/Contacts.controller.php", and a set of views in "app/view/contacts/".
-
Navigate to your application in your browser, with "/contacts" as the url. You should see the following screen:

Go ahead and try adding, updating, and deleting some Contacts. -
Lets add some simple validation to our Contact model. We want a Contact to always require a name at least. To do so, we modify our Contact.validate() method to look as follows:
public function validate() { $errors = Array(); if($this->name == '') $errors[] = 'Name is a required field'; return (count($errors) === 0 ? true : $errors); }
And thats it for now! As you can see, its really easy to get an Adroit application up and running, and not just a simple 'Hello World' application, but an application with complete CRUD functionality including database persistence.


