Quick Start

Last updated: February 12th, 2019

Download

You could download framework files from

Download CrowPHP Framework

Installation

Step One

Let's to change the environment configuration

Go to lib/configuration.json

{
    "useDatabase"                                   :       false,
    "appInDeveloping"                               :       true,
    "instanceDatabase"                              :       "Mysqli",

    "title"                                         :       "CrowPHP FRAMEWORK",

    "server"                                        :       "http://localhost/",
    "defaultKeyRouting"                             :       "sample",

    "dirModules"                                    :       "Apps",
    "dirLayouts"                                    :       "layouts",
    "mainHeaderLayout"                              :       "Header",
    "mainFooterLayout"                              :       "Footer",
    "dirProject"                                    :       "CrowPHP/",
    "dirLogs"                                       :       "logs",
    "dirMainFileJs"                                 :       "js",
    "dirMainFileCss"                                :       "css",

    "fileLayoutError"                               :       "error",

    "useStorageSession"                             :       false,
    "storageTable"                                  :       "sessions",
    "primaryKeyField"                               :       "record_id",
    "storageIdField"                                :       "session_id",
    "StorageDataField"                              :       "session_data",

    "localservers"                                  :       "localhost,127.0.0.1,localhost:8080",
    "cors"                                          :       false,
    "version"                                       :       "2.3"
}

There are different options, that you must change depending your application. let us explain it below

useDatabase This option can be 'true' or 'false' depending if you want that the app connect to database or not
appInDeveloping This option can be 'true' or 'false' depending if you want indicate that your app is in develop or not
instanceDatabase There are two option to connect to database server 'Postgresql' or 'Mysqli'
title General application title
server specify the domain server or ip server where the app will be run. Be sure if you use domain server write the 'http://' or 'https://'
defaultKeyRouting Write the main route that you specified in your router file Please check Routing!!
dirModules Main directory for all modules in the application
dirLayouts Main directory for all Layouts in the application
mainHeaderLayout Define main header layout
mainFooterLayout Define main footer layout
dirProject Main directory of application
dirLogs Main directory for all Logs in the application
dirMainFileJs Main directory for all JS in the application.
Note: this include JS directories into modules for the use Getting JS
dirMainFileCss Main directory for all CSS in the application.
Note: this include CSS directories into modules for the use Getting CSS
fileLayoutError If the framework detect a internal error, it will send you to error page. Here you could change that page.
note: this page must be into layout directory
useStorageSession This option can be 'true' or 'false' depending if you want that the application use session store by PHP you can see here
if you will use this option, follow this steps
storageTable Create into your database a new table 'session_data'
primaryKeyField Create a primary key field as 'record_id', this field must be AUTOINCREMENT
storageIdField Create a field 'session_id' to store SESSION ID
StorageDataField Create a field 'session_data' to store the SESSION DATA
localservers If your application will run in local server your must write the ip address in this option
annotation After version 2.1, CrowPHP changes your routing form, Its allowing the use of annotation. for that reason this field could not be change.
version For indicate in which version is the framework
cors Cross-origin resource sharing

Server Requirements

For the right functionality of CrowPHPFramework you need to have something requirements. These are specified bellow :

  • Apache *
  • PHP >= 5.4

Via Git Installer

First, download the CrowPHPFramework files using git:

    
        $ git clone https://
    

Structure

The Framework use different directories for its functionality and they are divided on :

Useful Tip:

Be sure to configure all options before start to create your structure

Modules

CrowPHP breaks down the application into modules for better management, these correspond to independent functionalities that will be handled by the corresponding module.

Note:

There is a modules directory that was generated by CrowPHP. You can find as 'Apps' into root path. You can change the name of this directory if you want, but you need specified this action into configuration.json

Module components
Layout

Within this directory are all the general designs that will be used by the different applications. you can change the name of this directory taking into account the file configuration.json

Please see Routing Layout

Header example
<!DOCTYPE html>
<html lang="en">

    <head>
        <title>CrowPHP Framework</title>
        <meta charset="utf-8">
        <meta http-equiv="X-UA-Compatible" content="IE=edge">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
    </head>
    <body>
        Add all content do you want...
Footer example

        Add all content do you want...
    </body>

</html>
Lib

In this directory you will find support libraries, some are totally necessary for the operation of the application. The others are utilities which you can implement when you want.

you can see these libraries here!

Logs

Within this directory will be save all files with the errors found through the application, the name of the file is composed of the reserved word error + date in progress

Example
error_00_00_000.txt
JS

Within this directory will be save all general JS files

CSS

Within this directory will be save all general CSS files

Routing

How we routing? using PHP annotation let see

<?php

class AnnotationController extends Acontroller
{
    /**
     * @Routing[value=home,type=html]
     */
    public function index() {
        return "index";
    }

    /**
     * @Routing[value=home/{id},type=html]
     */
    public function product($id) {
        Factory::setParametersView($id);
        return "index";
    }

}
?>

In this case is necessary to extends from Acontroller abstract class

Useful Tip:

You can see example file into Defaults/Controllers/AnnotationController.php

To route with annotations you must define @Routing[value=path] the path will be use to receive all requests with this name, if you want send a parameter you must write after / 'parameter option' like this @Routing[value=home/{anything}] the value into {} does not describe variable name that you receive as parameter in the function.

'type option' into @Routing will be define the response result of method, if you does not specify 'type option', the framework will be return a 'text value'.

If you choose 'html option' as a type, it will be charge the header layout and footer layout by default unless you write a specific layouts like this :

<?php
/**
* @Layouts[head=Header,foot=Footer]
*/
class AnnotationController extends Acontroller
{
    /**
     * @Routing[value=home,type=html]
     */
    public function index() {
        return "index";
    }

    /**
     * @Routing[value=home/{id},type=html]
     */
    public function product($id) {
        Factory::setParametersView($id);
        return "index";
    }

}
?>

Note:

if you use the html type. You must return the name of view into the current module or a html string



Using Layouts

There are two way to use layouts in CrowPHP

Here! we use the annotation @Layouts out of class. This you indicated that the class will use a layout for all request defined.
As long as you declared the type method as html

<?php
/**
* @Layouts[head=Header,foot=Footer]
*/
class AnnotationController extends Acontroller
{
    /**
     * @Routing[value=home,type=html]
     */
    public function index() {
        return "index";
    }

}
?>

Now, if you want to call different layouts, no matter what you are calling from the head of the class. You can do this by specifying the @Layouts annotation from the method that will receive the request

<?php
/**
* @Layouts[head=Header,foot=Footer]
*/
class AnnotationController extends Acontroller
{
    /**
     * @Layouts[head=exampleHeader,foot=exampleFooter]
     * @Routing[value=home,type=html]
     */
    public function index() {
        return "index";
    }

}
?>


The last type that you can specify is 'json' if you want that method return it.

<?php

class AnnotationController extends Acontroller
{
    /**
     * @Routing[value=home,type=json]
     */
    public function index() {
        return array("key" => "key option");
    }

}
?>

You can convert a complete controller class in REST CLASS, what's we are mean? that all class methods return a json.

<?php
/**
* @Rest
*/
class AnnotationController extends Acontroller
{
    /**
     * @Routing[value=home]
     */
    public function index() {
        return array("key" => "key option");
    }

}
?>

Useful Tip:

Remember to handle a json, you must return an array or object from PHP method

If you want to run a example, change the key annotation from configuration.json file to true

localhost/annotation

Factory

General methods of Factory class

<?php
/**
 * set a controller application object
 * @param \abstracts\Acontroller $controller
 */
public static function setController( $controller )

/**
 * @return mixed get current controller by application configured
 */
public static function get()

/**
 * define object by session variables
 * @return void
 */
public static function setSession()

/**
 * @return stdClass get object by session keys
 */
public static function getSession()

/**
 * @param $key ask for session key
 * @return bool
 */
public static function isSession( $key )

/**
 * verify if request variable was defined
 * @param string $name
 * @return boolean
 */
private static function isRequest( $name )

/**
* get Request Variable
* @param string $name
* @return mixed|null
*/
public static function getInput( $name )

/**
* get main path
* @return string
*/
public static function redirectTo()

/**
 * scape html
 * @param string $escapestring
 * @param flag $flags
 * @param string $charset
 * @param boolean $double_encode
 * @return string
 */
public static function escapeHtml($escapestring, $flags = ENT_QUOTES, $charset = 'UTF-8', $double_encode = TRUE)

/**
 * log error file
 * @param string $error
 * @return void
 */
public static function loggerError( $string )

/**
  * log warning file
  * @param string $string
  * @return void
*/
public static function loggerWarning( $string )

/**
  * log info file
  * @param string $string
  * @return void
 */
public static function loggerInfo( $string )

/**
  * log notice file
  * @param string $string
  * @return void
*/
public static function loggerNotice( $string )

/**
  * log debug file
  * @param string $string
  * @return void
 */
public static function loggerDebug( $string )

/**
  * log critical file
  * @param string $string
  * @return void
*/
public static function loggerCritical( $string )

/**
 *
 * @return array get parameters from view
 * array [ 0 => ??, 1 => 1 ]
 */
public static function getParametersView()

/**
 * render content view by defined keys of Web file
 * @param string $url url defined
 * @param array $params
 * @return string
 */
public static function renderView( $url, array $params = array() )

/**
 * Print content and die
 * @param $content mixed
 * @return void
 */
public static function printDie( $content )

/**
 * @param $content mixed
 * @return void;
 */
public static function printer( $content )

/**
 * render view with annotation
 * @param $url
 * @return mixed
 * @version 2.1
 */
public static function getView( $url )
?>

Bootstrap

You have access to GLOBAL variables, theses variables have different information as host, base path, directory separator, etc..
Also, if you use Language class in this file was defined main language. You can change it with your language if is necessary.

_BASE_ base path by operating system
_DS_ Directory separator by operating system
_DIR_MODULE_ Main module directory defined
_LAYOUT_ Main layout directory defined
_HOST_ Host name defined
_MAIN_DIRECTORY Main directory of application
_EXEC_APP This variable is for to know that the application has been charged successfully by framework