Skip to content
Codefii Php edited this page Apr 2, 2018 · 2 revisions

Stable Download Umstable License

About Codefii

Codefii is a superfast micro-framework, the first of its kind delivered as a general purpose framework to give acces and control and security to web Ninjas. Just as the name implies, codefii is a general purpose framework, it's doesn't force you to write in a particular pattern, once you have a prior knowledge of php you are good to go.

## Installation

firstly you need it installed on your system, its easy as typing the following command in your terminal by typing in the below code

1.

curl -s https://getcomposer.org/installer|php

after installing composer, launch your terminal or cmd, and type “composer” to check if it’s installed, you will see

  1. Composer

that show it’s installed. After getting all the required tools installed, the next thing is to get Codefii components installed in your working directory. For composer users, type the following command in your terminal through your working directory:

always clear your cache after installing composer by typing

3.composer clearcache

Creating a project

`composer create-project –prefer-dist codefii/codefii (your projectname)`

`composer create-project –prefer-dist codefii/codefii myblog`

## Database configuration

All the configuration files for Codefii framework is stored at **Database/Config**

<?php
$GLOBALS['config'] =  array(
'mysql'=>array(
'host'=>'127.0.0.1',
'username'=>'xxxxx',
'password'=>'prince',
'database'=>'codefi',
'encoding' => 'utf8',
'timezone' => 'UTC',
'cacheMetadata' => true,
'log' => false,
'port'=>8080
);

Working with Session

<?php
Session::set('user',Request::get('email'));
Session::register();

Checking if session is registered

<?php
if(Session::isRegistered()){
echo Session::get('user');//this would echo the session value
}

//checking if session is destroyed
if(Session::isDestroyed()){
    Redirect::to('index');
}

What the above code does is to set a session key and value and register it

## Routing

Routing lets you create your own URL paths, based on the path you can load a controller and its method. The routes is located in Routes directory


<?php
$router = new Network\Router\Router();
$router->dispatch($_SERVER['QUERY_STRING']);

The first two lines of codde defined in your Routes doesn't need to be tampered with.

## Basic Routing

Imagine for instance we have a controller with the name Hello and a method index extending the base controller class Controller. We want to access our controller's method index on the browser upon page load


<?php
$router = new Network\Router\Router();
$router->routes('',['controller'=>'Hello','action'=>'index']);
$router->dispatch($_SERVER['QUERY_STRING']);

Routing with parameters using regular expression

Regular express here is the same as the one you know. However, we only cover a little part of the Regex here. When defining a routes paramaters such as Post ID in a registered URL: e.g localhost/codefii/post/33 here is how to go about it:


<?php
$router = new Network\Router\Router();
$router->routes('post/{id:\d+}',['controller'=>'Hello','action'=>'post']);
$router->dispatch($_SERVER['QUERY_STRING']);
    

The reason for \d+ is because you are setting a defined rule that will accept only integers

In a case whereby you want to pass a set of alphanumeric characters as URL paramaters for instance localhost/codefii/blog/hWdid23094ddj3SdD3k here is how to achieve it in regular expression


<?php

class Hello extends Controller {
 public function post(){
     echo $this->route_params['user_id'];
 }
}

In standard php, if we are to rewrite localhost/codefii/blog/hWdid23094ddj3SdD3k, this will be localhost/codefii/blog.php?user_id=hWdid23094ddj3SdD3k. From our regular expression, we defined user_id to be a set of all possible alphanumeric characters inclding white spaces

Redirect

Codefeii provides a unique way of ridirecting to other pages after a given action has been performed. When using the Redirect classs, the method to which specifies the end point of the routing is called. Here is how it can be implemented


<?php
Redirect::to('profile');

Controllers

The controller is responsible for handling the user interface and application. It is responsible for rendering response with the aid of both the model and the view structure. In my case I choose to call the controller the boss because he ensures a sanitized ineteraction between the model and the view. The controller is where all the validation rules is been executed before sending data to the model for processing.


namespace Codefii\Controller;
use Network\Controller\Controller;
class HomeController extends Controller{
    public function index(){
        //do something here
    }
}

Empty Controller

In codefii, you can aswell perfom a database interaction in the controller without having to create any model class to handle your queries / database interaction. In our case, we choose to call such query style Surface Query simply because the controller can render a raw data to the view or to a web page without any view file being created. Take for instance


<?php
use Network\Controller\Controller;
class MyApp extends Controller{
    public function index(){
        echo "welcome to my first codefii app";
    }
}

Then if you want to display some record from databse using the controller here is how to go about it


<?php
use Network\Controller\Controller;
use Network\Model\Model;
class MyApp extends Controller{
    public function index(){
        $users = Model::getDb()->query("SELECT * FROM users")->results();
        var_dump($users);
    }
}

Contribution

Hello, i am so excited for showing interest in contributing to the development of this wonderful project. Before contributing, i advise you read through the contribution terms.

## Directory Structure


Codefii/ internally used build tools(development files)
public/ static files
vendor/ core framework code

Community


Participate in discussions at forum.
Community chat on slack.
Follow us on twitter @codefii1.

Reporting Security issues

If you discover any vulnerability or have any issues you would like to report kindly message the project manager at Prince Darlington

License

The Codefii framework is open-sourced software licensed under the MIT license.

Acknowledgement

The Codefii team would like to thank Soodaroft, all the contributors to the Codefii project and you, the Codefii user.