ariffazmi / light-php-framework
此软件包的最新版本(dev-master)没有提供许可证信息。
Light php MVC
dev-master
2017-01-02 06:35 UTC
Requires
- php: >=5.3.0
- philo/laravel-blade: 3.*
- php-di/invoker: ^1.3
- pimple/pimple: ^3.0
- rdlowrey/auryn: ^1.4
- riimu/kit-csrf: 2.*
- rych/phpass: 3.0.*@beta
This package is not auto-updated.
Last update: 2020-01-14 20:34:16 UTC
README
安装应用程序
Composer
从github仓库下载。在你的终端运行 composer install
。
如何使用
打开根目录下的 .htaccess 文件。然后更改此值以匹配文件夹目录名称
RewriteEngine On
RewriteBase /replace-your-directory-folder-name
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.+)$ index.php?uri=$1 [QSA,L]
服务器环境
进入此项目的根目录,然后在你的终端运行此命令。
php pfw setServerEnv yourserverlocation serverusername serverpassword serverdatabase
或者你可以编辑 Pfw/App/Pfw/Server.php 文件
define('SERVERLOCATION', '');
define('SERVERUSERNAME', '');
define('SERVERPASSWORD', '');
define('SERVERDATABASE', '');
路由
require 'vendor/autoload.php';
use App\Pfw\Main as App;
$app = new App([
'debug' => true
]);
//POST
$app->post('/saveUser', function() use($app){
echo "User Saved! ";
});
//GET
$app->get('/', function() use($app){
echo "Hello, im your home page.";
});
//GET WITH PARAMETER
$app->get('/hello/.+', function($name) use($app){
echo "Hello, $name.";
});
使用控制器进行路由
//POST
$app = new \App\Main\Pfw([
'debug' => true
]);
$app->post('/saveUser', function() use($app){
$app->controller("UserController@save");
});
//GET
$app->get('/', function() use($app){
$app->controller("HomeController@index");
});
//GET WITH PARAMETER
$app->get('/hello/.+', function($name) use($app){
$app->controller("HomeController@greetings",$name);
});
模型
=======================
Example model for User:
=======================
namespace App\Models;
/**
* @return User data
*/
use \App\Pfw\Model;
Class User extends Model{
protected $table = 'users';
}
============================
Meanwhile in UserController:
============================
namespace App\Controllers;
use \App\Pfw\Main as App;
use \App\Http\Request as Request;
use \App\Models\User as User;
//For store data
public function store()
{
$user = new User();
$user->fname = "John Doe";
$user->email = "johndoe@gmail.com";
$user->mobile_no = "60123456789";
$save = $user->save();
}
//For update data
public function update()
{
$user = new User();
$user->id = 15;
$user->fname = "John Doe 1";
$user->email = "johndoe1@gmail.com";
$user->mobile_no = "60123456789";
$save = $user->save();
}
//For delete data
public function delete()
{
$user = new User();
$user->id = 15;
$delete = $user->delete();
}
//For request form data
public function reqFormData(){
$req = new Request();
echo $req->username;
}
//For finding data based on user id
public function FindByUid(){
$user = new User();
echo "<pre>";
//Put your id as parameter to that function
print_r($user->FindByUid(3));
}
//For finding data based on user id and email
public function FindByUidAndEmail(){
$user = new User();
echo "<pre>";
//Put your id as parameter to that function
print_r($user->FindByUidAndEmail(3,'john.doe@gmail.com'));
}
//For finding data based on user id or email
public function FindByUidOrEmail(){
$user = new User();
echo "<pre>";
//Put your id and email as parameter to that function
print_r($user->FindByUidOrEmail(3,'john.doe@gmail.com'));
}
//For finding data based on user id between specific range
public function FindByUidBetween(){
$user = new User();
echo "<pre>";
//Put your range as parameter to that function
print_r($user->FindByUidBetween(0,10));
}
//For finding data based on user id less than specific range
public function FindByUidLessThan(){
$user = new User();
echo "<pre>";
//Put your range as parameter to that function
print_r($user->FindByUidLessThan(10));
}
//For finding data based on user id less greater than specific range
public function FindByUidGreaterThan(){
$user = new User();
echo "<pre>";
//Put your range as parameter to that function
print_r($user->FindByUidGreaterThan(10));
}
//For finding data based on user status is null
public function FindByStatusIsNull(){
$user = new User();
echo "<pre>";
//Put your range as parameter to that function
print_r($user->FindByStatusIsNull());
}
//For finding data based on username like without %% symbol
public function FindByUsernameLike(){
$user = new User();
echo "<pre>";
//Put your name as parameter to that function
print_r($user->FindByUsernameLike('John Doe'));
}
//For finding data based on username like with %% symbol
public function FindByUsernameContaining(){
$user = new User();
echo "<pre>";
//Put your name as parameter to that function
print_r($user->FindByUsernameContaining('John Doe'));
}
"username" as the example of <input type="text" name="username">
生成控制器
控制器文件夹位于 Pfw/App/Controllers/。
进入此项目的根目录,然后在你的终端运行此命令。
php pfw makeController UserController
生成模型
模型文件夹位于 Pfw/App/Models/。
进入此项目的根目录,然后在你的终端运行此命令。
php pfw makeModel User
就这样!现在去构建一些酷的东西吧。