Discover Cygnite Framework to make your work simple and better.

Framework
The high performance and user friendly PHP framework.

Quickstart


Documentation

Quick Start

  • Install and Configuration
  • Creating Controller
  • Creating Model
  • Creating View
  • Routing
  • Display Data in View

Install and Configuration

No complicated xml/yaml configuration files. Simply install latest software via composer, configure your database connection inapps/configs/database.phpand you are ready to start your awesome application.

Install via Composer

Cygnite Framework is powered by Composer for dependency management. The best and recommanded way to install Cygnite Framework is to download composer.phar to your local directory or to use globally on your system, move it to usr/local/bin. For windows users please download composer and install composer setup.

You may install Cygnite Framework either simply downloading skeleton application from github repository or you may install via composer. Composer installation is more convenient.

Now open terminal (Command prompt window for windows) and go to directory where you want to install Cygnite Framework.

Composer Create Project

  
composer create-project cygnite/cygnite-application cygnite
or
composer.phar create-project cygnite/cygnite-application cygnite

The above command will create a skeleton project inside your current directory. Change cygnite/composer.jsonas below to download your dependencies.

Replace -
 
"require": {
    "php": ">=5.3.3"
},
"autoload": {
   "psr-0" : {
       "Cygnite\\" : "src/"
   }
}


With -
 
"require": {
     "php": ">=5.3.3",
     "cygnite/framework": "1.0.6",
     "filp/whoops": "1.0.10",
     "twig/twig": "1.*",
     "symfony/console": "2.3.*"
 },
 "autoload": {
     "classmap": [
          "apps/controllers",
          "apps/models",
          "apps/components" 
     ],
     "psr-0" : {
      "Cygnite\\" : "src/"
     }
 }

Composer: Install Dependencies

Enter below command in your terminal to simply update your dependencies.

 
composer update

That's all you are ready to build your awesome application.

Server Requirements

The Cygnite framework has a very few system requirements:

  • > PHP >= 5.3x
  • > MCrypt PHP Extension

Creating Controller

To get started, there are sample controller available inside apps/controllers directory. You can also create controller.

    
namespace Apps\Controllers;

use Cygnite;
use Cygnite\AbstractBaseController;

class UsersController extends AbstractBaseController
{
   public $author = 'Sanjoy Dey';

   public function __construct()
   {
       parent::__construct();
   }

   public function indexAction()
   {
      echo 'Hello World!!';
   }
}

Creating Model

Cygnite Skeleton application also shipped with sample model into your apps/models/ directory. You can create your model in same directory to interact with your database. Your model class name should be StudlyCaps, every model class act as simple orm to map your database tables as objects, Cygnite Model follows ActiveRecord style highly inspired by ruby on rails. Your table name must be lowercase followed by underscore prefix.

Example- If your table name is guest_book than your model name should be GuestBook.

    
namespace Apps\Models;

use Cygnite;
use Cygnite\Database\Schema;
use Cygnite\Database\ActiveRecord;

class GuestBook extends ActiveRecord
{
   /**
    * Your database name goes here
    * @param database 
    */
    protected $database = 'cygnite';

   /**
    * @param $tableName
    * Optional. If you don't provide table name here class will act as database table.
    */
    //protected $tableName = 'guestbook'; 

   /**
    * Primary key of your table
    */
    protected $primaryKey = 'id';

    public function __construct()
    {
        parent::__construct();
    }
}

Creating View

Next, let's create simple view to display our welcome page which is reside in apps/views directory. Example-

 
    <html>
    <body>
        <h1>Cygnite Framework QuickStart</h1>
            Congrats !! You have created your first view page.
    </body>
</html>

You can also create template layout and render the sections into it. Cygnite Framework has built in support for most elegant and powerful twig template engine. For more details check Views

Routing

Cygnite Framework has powerful routing features. You can use routerconfig.php inside your apps directory. Also you can write powerful rest api with simple closure object with routes.php. Cygnite Framework also gives you flexibility to call controller with parameters from your router directly.

Let us create our first routing.

Example -

1. For direct routing use routerconfig.php .
 
    return array(
       '/sayhello/(\w+)/(\d+)'             => 'home.test',
       '/blog(/\d{4}(/\d{2}(/\d{2}(/[a-z0-9_-]+)?)?)?)?'          => 'home.crons'
    );

2. router.php has closure support.
    

    // Before Router Middleware
    $router->before('GET', '/.*', function() {
          echo "Cygnite Framework has awesome features ";
          Router::end();
    });
    $router->run();

For brief details please have a look into routing guide.

Display Data Into View

Let us see how to display data into view.
 
     $this->render("welcome")->with(array(
                                    'author'=>$this->author,
                                    'email'=>'sanjoy09@hotmail.com',
                                    'messege' => 'Welcome to Cygnite Framework',
                                   ));

You need to assign values to view as by simply passing values to with function. You can get the data into the view (if plain php file used as view) or in layout as follows
    
echo $this->author;
echo $this->email;

Generating Crud

Cygnite CLI now makes your job much more simpler. You can create simple crud operation via terminal. For more details have a look at Cygnite CLI - Crud Generator


Follow Us On Facebook Twitter Google+ Linkedin
Released Under The MIT Public License. Copyrights @2013-2014. Powered by- Sanjoy Dey Productions.