alisahanyalcin/infinity-core

InfinityCore 是一个用于构建 Web 应用的 PHP 框架。

资助包维护!
Patreon

安装: 2

依赖项: 0

建议者: 0

安全: 0

星标: 1

关注者: 2

分支: 0

开放问题: 0

类型:项目

1.0.0 2022-01-16 16:32 UTC

This package is auto-updated.

Last update: 2024-09-25 19:44:49 UTC


README

InfinityCore 是一个用于构建 Web 应用的 PHP 框架。

安装

通过 composer 创建项目

composer create-project alisahanyalcin/infinity-core:dev-master app-name
cd app-name

或直接运行以下命令

git clone https://github.com/alisahanyalcin/InfinityCore.git
cd InfinityCore
composer install

基本用法

您可以在 Wiki 中找到完整的文档。

配置

Application/config/AppConfig.php

const base_url = 'https:///InfinityCore/';

// development, production, testing
const ENVIRONMENT = 'production';

const TIMEZONE = 'Europe/Istanbul';

Application/config/DBConfig.php

const dbConfig = [
    'debug'     => true,
    'host'      => 'localhost',
    'driver'	=> 'mysql',
    'database'	=> 'testDB',
    'username'	=> 'root',
    'password'	=> '',
    'charset'	=> 'utf8',
    'collation'	=> 'utf8_general_ci',
    'prefix'	=> ''
];

Application

<?php
require __DIR__ . '/vendor/autoload.php';
use InfinityCore\Core\Application; // import the application class

$app = new Application(); // Create new application
*here you can add your routes*
$app->run(); // run the application

路由

示例路由定义

$app->router->get('/', 'HomeController@index');
$app->router->get('/about', 'HomeController@about'); // return view about page with data from database PDOx class

错误

示例错误: index.php

use InfinityCore\Application\config\AppConfig;

//e.g. test 404 - Not Found
$app->router->error(function () use ($app) {
    $app->load::view('errors/'.AppConfig::pageNotFoundErrorView, [
        'statusCode' => '404',
        'messageTitle' => 'Page Not Found',
        'message' => 'Sorry, but the page you were trying to view does not exist.'
    ]);
});

控制器

<?php

namespace InfinityCore\Application\controllers;

use InfinityCore\Core\BaseController;

class HomeController extends BaseController
{
    public function __construct()
    {
        parent::__construct();
    }

    public function index()
    {
        $this->load->view('home', ['name' => 'InfinityCore']);
    }

    public function about()
    {
        $records = $this->model->getModel('HomeModel')->getRecords();

        $this->load->view('about', ['name' => 'About Page', 'records' => $records]);
    }
}

视图

index.php

<h1>
    Welcome to{% if name %} {{name}} {% endif %}
</h1>
<p>
    {{name}} is a PHP framework for building web applications. // print name
</p>

about.php

<h1>
    Welcome to
    {% if name %}
    {{name}}
    {% endif %}
</h1>
<p>
    {% for record in records %}
        <br> > {{record.name}}:{{record.email}}
    {% else %}
        No users have been found.
    {% endfor %}
</p>

数据库

示例数据库

CREATE TABLE `testdb`.`users`
(
    `id` INT NOT NULL AUTO_INCREMENT ,
    `email` VARCHAR(256) NOT NULL ,
    `name` VARCHAR(256) NOT NULL ,
    PRIMARY KEY (`id`)
)   ENGINE = InnoDB CHARSET=utf8 COLLATE utf8_general_ci;