PHPackages                             thnguyendev/phpwebcore - 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. [HTTP &amp; Networking](/categories/http)
4. /
5. thnguyendev/phpwebcore

ActiveProject[HTTP &amp; Networking](/categories/http)

thnguyendev/phpwebcore
======================

PHPWebCore framework

1.0.0(4y ago)281MITPHPPHP &gt;=7.0

Since Oct 23Pushed 4y ago2 watchersCompare

[ Source](https://github.com/thnguyendev/PHPWebCore)[ Packagist](https://packagist.org/packages/thnguyendev/phpwebcore)[ RSS](/packages/thnguyendev-phpwebcore/feed)WikiDiscussions main Synced 1w ago

READMEChangelog (1)Dependencies (3)Versions (2)Used By (0)

PHPWebCore 1.0.0
================

[](#phpwebcore-100)

PHPWebCore is a MVC framework in PHP. It is built on the habits of using ASP.NET Core. It aims to be simple and easy to use. PHPWebCore implements PSR-7 HTTP message interfaces and PSR-17 HTTP Factories. It also supports dependency injection.

PHPWebCore is a very basic framework. But, you can always include any PHP packages that need for your app, for instance, RedBeanPHP, Doctrine ORM, Firebase PHP-JWT, php-amqplib, etc...

Quick start
-----------

[](#quick-start)

1. PHPWebCore needs Composer and of course PHP. Make sure you download and install [PHP](https://www.php.net/downloads.php) and [Composer](https://getcomposer.org/download).
2. Create PHPWebCore project by Composer. Then, run the update command from Composer to download all of denpendencies. ```
    composer create-project thnguyendev/phpwebcore [project name]
    cd [project name]
    composer install
    ```
3. The web root folder is "public" in project folder. There are several ways to run the app: use the PHP built-in server, Apache server or Nginx server, etc.. For PHP built-in server, you just need to set the document root is "public" folder. In Apache server, .htaccess file is ready in "public" folder, you need to set "public" folder is Apache web root directory. If you use Nginx server, you need to add a server in nginx.conf which has root points to "public" folder in app and setup location like below.
    - PHP built-in server

    ```
    php -S localhost -t /public
    ```

    - Apache server .htaccess config

    ```
    RewriteEngine On
    RewriteCond %{REQUEST_FILENAME} !-f
    RewriteCond %{REQUEST_FILENAME} !-d
    RewriteRule ^(.*)$ index.php?q=$1 [QSA,NC,L]
    ```

    - Nginx server nginx.conf config

    ```
    root        /public;
    location / {
        index  index.html index.htm index.php;
        if (!-e $request_filename) {
            rewrite ^(.*)$ /index.php?q=$1;
        }
    }
    ```
4. Now back to the app, your workspace in the app is just inside the "src/app" folder. Working with the routes of web app is our first step. PHPWebCore does not use the PHP attributes for the routing. The default routing is the Route class extends from PHPWebCore\\AppRoute in Route.php. You need to implement initialize() method for Route class. Routes should be defined here. The request Url paths split into paths and parameters. PHPWebCore will map it to the first route that has the most segments in path. In this example, we create 2 routes: one is the root path and the other is also the root path but it has "name" as parameter.
    - \[project folder\]/src/app/Route.php

    ```

    ```
8. Finally, your first PHPWebCore app is ready. Run your app and try it. Use the following Urls in your browser.
    - http://\[your host\]
    - http://\[your host\]/\[name\]

Web API
-------

[](#web-api)

In this tutorial, we will create a PHPWebCore Web API app. First thing first, you need to create a PHPWebCore project.

1. When you have your project, define your API route that uses GET method. This api just simply returns the information of your project in JSON.
    - \[project folder\]/src/app/Route.php

    ```

    ```
2. Next step is creating ProjectController.php of the controller in "Controllers" folder. Set the response content type is application/json.
    - \[project folder\]/src/app/Controllers/ProjectController.php

    ```
