Creating A Task List Using Craft Console


Creating A To-Do List:

Our previous article was on "Travis CI: Continuous Integration for PHP Project". A very happy new year. It is this year's first tutorial for appsntech.com readers. In this article I will discuss How To Create A Simple To Do List Using Craft Console (Cygnite Component). In this tutorial we will be using Cygnite PHP Framework v2.x.

I will not explain how to install cygnite framework & configure database connections, as it is already explained in its beautiful documentation. Cygnite directory structure explained here.

What is Craft Console?

Craft introduced in Cygnite v2.0. Craft is console based powerful code generator provided by Cygnite Framework. It is built on top of Symfony console component.

It helps you to create and generate fully customized Controllers, Models, Forms, Migrations, Commands, CRUD for database and more. To access craft in Cygnite, just go to:


cd /var/www/cygnite/console/bin/

Execute below command to see list of available commands for your application.


php craft list

To demonstrate, I will use Craft for building our simple To-Do list. Let's get started.

Creating a Table For To-Do List:

Configuration of database connection explained here. Once you have configured database connection. Let us create a new table for our "To-Do app".

Meet Migration & Schema Builder:

Before doing anything else we need to build a table schema. Cygnite has a Schema Builder to help you building table schema and Migrations class to build create database version control.

All though you can create a table schema executing query. But recommended way to build table schema is using Migrations . Execute below command to generate your migration file.


php craft migrate:init to_do

Go to /src/Apps/Resources/Database/Migrations/ directory and find out the file with name xxxx_to_do.php. Edit the file add below lines of code inside "up" method .


//Your schema to migrate
Schema::make('to_do', function ($schema)
{
    $schema->create([
            ['column'=> 'id', 'type' => 'int', 'length' => 11,
             'increment' => true, 'key' => 'primary'],
            ['column'=> 'title', 'type' => 'string', 'length' =>100],
            ['column'=> 'description', 'type' => 'string', 
             'length'  =>16],
            
            /*..Add columns to your table schema .*/
            ['column'=> 'created_at', 'type' => 'datetime', 
             'length' => 'null'],
            ['column'=> 'due_date', 'type' => 'datetime', 
             'length' => 'null'],

    ], 'InnoDB', 'latin1');
});


Execute below command to create table schema.


php craft migrate

You will see the below message in your console:

Now your "to_do" table is ready to store some tasks.

Generating CRUD Using Craft:

You don't have to do much stuff as Craft commands are ready to generate most of the stuffs for you. Open the console window and from the root directory of your project, go to /var/www/cygnite/console/bin/ directory and issue below command.


php craft generate:crud todo to_do

Your to do manager is ready, let us add a single route to the controller to test the newly created app by executing CRUD operations.

Open /var/www/cygnite/src/Apps/Routing/RouteCollection.php, add a route as below in the executeStaticRoutes() method.


$this->routesController->controller('Todo');

Go to the url: http://localhost/cygnite/todo/ You will see below screen.

This page will display empty records in the grid as we didn't add any to do tasks.

Creating And Updating the To-Do List

Let us add a new tasks by clicking Add Todo button. You will land to below form. Now let us add a new to-do task using this form.

Once you added a new to do task you will be redirected to task list page.

Now let's say added to do task needs to be updated. Click Edit button in the grid, it will take you to edit form.

Click on save button once you updated the Todo, it will update the todo list and redirect you to list page. You will see screen as below.

Liked this? Read these!

  1. Get Started With Test Driven Development: Unit Testing With PHPUnit?
  2. Backbone JS vs Angular JS- Uncovering key differences
  3. 5 Best Things You Should Know About PHP 7
  4. Facebook style wall posting using Cygnite PHP Framework, Jquery, Ajax

Wrapping Up:

I have explained you how to create a simple To-Do list using Cygnite Framework. That’s all for this tutorial. Isn't easy? This is just a basic tutorial. You can do much more. So now it’s your turn, give it a try. Use Cygnite framework, save time. You will be up and running fast.

Hope you like this tutorial and many more useful posts to publish for this year. If you have any questions, please let us know by posting your comments below. Please don't forget to share or like this article with your friends. Thanks for reading.

Follow Us On Facebook Open Source Web Developers by Appsntech facebook group Twitter Open Source Web Developers by Appsntech twitter group Google+ Open Source Web Developers by Appsntech Google group Linkedin Open Source Web Developers by Appsntech, LinkedIn group
Copyright @2011-2015 appsntech.com. All rights reserved. Powered By- Sanjoy Dey Productions