PHPackages                             pejman/peji - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. pejman/peji

ActiveLibrary

pejman/peji
===========

v1.0.7(4y ago)032MITPHP

Since Mar 16Pushed 4y ago1 watchersCompare

[ Source](https://github.com/pejman-hkh/peji)[ Packagist](https://packagist.org/packages/pejman/peji)[ RSS](/packages/pejman-peji/feed)WikiDiscussions master Synced 1mo ago

READMEChangelogDependenciesVersions (3)Used By (0)

Peji
====

[](#peji)

Peji initialize database, config, view, model

```
use Peji\DB\DB as DB;
use Peji\Config as Config;
use Peji\View as View;

Config::setDir('../config');
$dbConf = Config::file('db');

define('siteUrl', $_SERVER['REQUEST_SCHEME'].'://'.$_SERVER['HTTP_HOST'] );

DB::init( $dbConf['host'], $dbConf['username'], $dbConf['password'], $dbConf['db'] );

DB::setAttr([
	\PDO::MYSQL_ATTR_INIT_COMMAND => "SET NAMES 'utf8'" ,
	\PDO::ATTR_PERSISTENT => false ,
	\PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => true ,
]);

View::setDir( '../app/View' );

try {
	require_once '../route/route.php';
} catch( Error $e ){
	Peji\Error::manage( $e );
}
```

Peji Routing ...

```
use Peji\Router as Router;
use Peji\View as View;

function pageNotFount($get = []) {
	return Peji\Bootstrap::start( 'user', 'notfound', 'index', 0, [], $get );
}

Router::setPath( getPath() );

Router::route('admin/{controller?}/{action?}/{id?}', function( $controller = 'index', $action = 'index', $id = 0 ) {
	$params = Router::params();
	$count = count_not_empty( $params );

	if( $count % 2 == 1 )
		array_shift( $params );

	if( ! Peji\Bootstrap::start( 'admin', $controller, $action, $id, $params ) ) {
		pageNotFount();
	}
})->where( ['controller' => '[a-zA-Z]+', 'action' => '[^\/]+', 'id' => '[^\/]+'] )->setExtension( [ 'html', 'txt' ] )

->elseRoute( '{:all}', function( $p ) {

	$controller = urldecode($p[0])?:'index';

	$action = urldecode(@$p[1]?:'index');
	$id = urldecode(@$p[2]);
	array_shift( $p );
	array_shift( $p );

	$e = explode(".", $controller);
	$controller = $e[0];

	if( ! Peji\Bootstrap::start( 'user', $controller, $action, $id, $p ) ) {
		if( ! Peji\Bootstrap::start( 'user', 'page', 'index', $controller, $p )  ) {
			pageNotFount();
		}
	}

});

Router::dispatch(function( $status ) {

	if( $status == 404 ) {
		pageNotFount();
	}
});
```

Peji Model

```
