Download the PHP package comfyphp/core without Composer
On this page you can find all versions of the php package comfyphp/core. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download comfyphp/core
More information about comfyphp/core
Files in comfyphp/core
Package core
Short Description Write PHP comfortably with ComfyPHP
License MIT
Homepage https://github.com/comfyphp/core
Informations about the package core
Write PHP comfortably with ComfyPHP
Provide an better development environment for developers who targeting specialized environments, such as Internet Explorer or environments where JavaScript is disabled.
Framework Directory Structure
Before Using it
Required dependencies for ComfyPHP:
Download / Install
To use this framework, you can install it with Composer.
Basic public/index.php
format
You can create index.php
inside the public folder like the example provided below:
Or just add the fileBasedRouter()
function into the index.php
for File-Based Routing which will be introduced later.
Basic src/pages/_document.php
Format
Both <!--%head%-->
and <!--%body%-->
will work as a regex to be replaced by <head>...</head>
and <body>...</body>
from each page, please do not delete it when editing the document.
Basic src/pages/page.php
Format
Inside each webpage, there are two sections: <head>...</head>
and <body>...</body>
. You can customize the content in both the head and body of each page by making edits. However, if both the <head>...</head>
and <body>...</body>
sections are missing from the file, ComfyPHP will recognize it as an API controller and provide all the results captured from it.
Config composer.json
You can config composer.json
to run ComfyPHP scripts.
or just run the command manually:
Development Mode
Start the application with development env:
Build for Production
To build the env for production server:
Then you can use apache/nginx to take care of the server.
Production Mode Preview
Start the application with production env:
Server Port
Server will run in http://localhost:3000 by default, you can add the port parameter to the script in order to set up the server port:
Routing
There are two methods available for routing: function-based routing and file-based routing. You have the freedom to choose either method based on your preference.
Function-Based Routing
When utilizing Function Based Routing, ComfyPHP will automatically search for a PHP file in /src/pages
that matches the name mentioned in /public/index.php
. By default, if you enter get("/alphabet", "abc");
, it will look for /src/pages/abc.php
. If you haven't created a file with the same name, it will return no results. Additionally, you can use methods other than get
, such as post
, put
, patch
, delete
, head
, options
, trace
and connect
.
File-Based Routing
To implement File Based Routing, simply include fileBasedRouter();
in /public/index.php
. This enables ComfyPHP to search within the /src/pages
directory when a user visits the site. For instance, when a user visits /settings/themes?abc=123
with any major HTTP methods, ComfyPHP will look for a file named settings/themes.php
inside the pages
folder. If such a file doesn't exist, ComfyPHP will then search for settings/themes/index.php
instead. It will only return no results if neither themes.php
nor index.php
files are created.
About .env
To store different environment variables, you can create multiple .env files, with their priorities determining the order as shown below:
-
Development mode
.env.development.local
>.env.development
>.env.local
>.env
-
Production mode
.env.production.local
>.env.production
>.env.local
>.env
Example
You can add different variables inside the env files like the example below:
After the process, you can use the variables within the pages.
404 Error Handling
For the 404 error, ComfyPHP will send a 404 status back to the client. You can add a file named _404.php
to the pages
folder. This file will serve as the error handling page when a client tries to access a page that cannot be found in the router.
Tool Functions
ComfyPHP provides you with some useful tools to simplify building your project. You may take a look at them.
But don't forget the initialize the class first before using them:
useLog
This function helps you print console.log messages in JavaScript.
useError
This function helps you print console.error messages in JavaScript.
useFilter
This function helps you escape some special values that may cause XSS attacks.
Reserved Variables of ComfyPHP
License
This project is MIT licensed, you can find the license file here.