Code Monkey home page Code Monkey logo

aier's Introduction

Aier

A Simple PHP Frame


这是个很轻很小的框架,可以快速开发移动端和web端

This is a small frame, and fast development for mobile or web.

安装 Installation

$ cd Aier
$ composer update
$ composer dump-autoload

DEMO

路由 Route

在 config/route.php 配置文件中添加路由:

Add routes in config/route.php:

use Evai\Tenden\Tenden;

Tenden::any('/', function() {
  echo "Welcome";
});

Tenden::get('/name/(:all)', function($name) {
  echo 'Your name is '.$name;
});

Tenden::get('home', 'HomeController@home'); //your controller class

Tenden::error(function() {
    throw new Exception("404 Not Found"); //not found route then write
});

Tenden::dispatch(); //Don't forget add in the end

发送邮件 Email Send

假设现在你创建了一个HomeController.php控制器文件:

For this demo lets say you have a folder called controllers with a HomeController.php

class HomeController extends BaseController
{

function email()
{
	Mail::to(['[email protected]'])
        ->from('Evai <[email protected]>')
        ->title('Hello World')
        ->content('<h1>Hello World !</h1>');

		echo '发送邮件成功';
}

模型 Model

在创建模型之前,请确保你的mysql服务已经开启并可以正常访问。然后打开 config/database.php 进行配置。

Before you create the model, make sure your MySQL service is turned on and can be accessed properly. Then open config/database.php for configuration.

我们创建一个新的用户模型:

We will create a new Users Model:

<?php

use Illuminate\Database\Eloquent\Model;

class Users extends Model
{

    public $table = 'users'; //your table name

    public $primaryKey = 'userid'; // your primary key

}

更多的用法请参考:[Eloquent] (https://laravel.com/docs/5.3/eloquent)

For more example refer to:[Eloquent] (https://laravel.com/docs/5.3/eloquent)

视图装载 View

在 HomeController 中添加如下:

Add HomeController:

public function home()
{
    $user = Users::find(1); //your model

    return View::make('home') //your template
        ->with('user', $user)
        ->withTitle('Aier')
        ->withShowMsg('hello Aier');
}

这个模板文件在 app/Views/home.php 文件,你可以来这样获取变量:

This template in app/Views/home.php , you can get variables look like:

<!DOCTYPE html>

<html lang="en">

<head>

    <meta charset="UTF-8">

    <title><?php echo $title ?></title>

</head>

<body>

<div class="article">

    <h1><?php echo $user['name'] ?></h1>

    <div class="content">

        <?php echo $user  ?>

    </div>

</div>

<ul class="msg">

    <h1><?php echo $show_msg ?></h1>

</ul>

</body>

</html>

Redis

在 HomeController 中添加如下:

Add HomeController:

function redis()
{
    Redis::set('name', 'Evai', 5);

    echo Redis::get('name');

}

如果你新建了一个控制器或模型,请务必执行下 composer dump-autoload 命令。

if you create a new Controller or Model, please run command : composer dump-autoload.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.