Yaf使用composer管理模塊

1.安裝YAF

2.在NGINX上配置YAF

注意:
項(xiàng)目根目錄public

==更改項(xiàng)目根目錄,必須加上去,否則無法使用默認(rèn)路由(實(shí)路由URL重寫功能)==

if (!-e $request_filename) {
        rewrite ^/(.*\.(js|ico|gif|jpg|png|css|bmp|wsdl|pdf|xls)$) /public/$1 last;
        rewrite ^/(.*) /index.php?$1 last;
    }
#
# The default server
#
server {
    listen          90;
    server_name     demo.ywz;
    root   /usr/share/nginx/yafmy/public;
    index  index.php index.html index.htm;

    if (!-e $request_filename) {
        rewrite ^/(.*\.(js|ico|gif|jpg|png|css|bmp|wsdl|pdf|xls)$) /public/$1 last;
        rewrite ^/(.*) /index.php?$1 last;
    }

    if ($http_user_agent ~ ApacheBench|webBench|Java/|http_load|must-revalidate|wget) { 
        return 403; 
    }

    error_page  404              /404.html;
    location = /404.html {
        root   /usr/share/nginx/html;
    }

    # redirect server error pages to the static page /50x.html
    #
    error_page   500 502 503 504  /50x.html;
    location = /50x.html {
        root   /usr/share/nginx/html;
    }

    # proxy the PHP scripts to Apache listening on 127.0.0.1:80
    #
    #location ~ \.php$ {
    #    proxy_pass   http://127.0.0.1;
    #}

    # pass the PHP scripts to FastCGI server listening on 127.0.0.1:9000
    #
    location ~ \.php$ {
 
        fastcgi_buffers 2 256k;
        fastcgi_buffer_size 128k;
        fastcgi_busy_buffers_size  256k;
        fastcgi_temp_file_write_size  256k;

        fastcgi_pass    127.0.0.1:9000;
        fastcgi_index   index.php;
        #fastcgi_param  SCRIPT_FILENAME  /scripts$fastcgi_script_name;
        fastcgi_param   SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include         fastcgi_params;
    }
  
}

3.安裝composer

wget https://getcomposer.org/composer.phar建議在家目錄下載
chmod +x composer.phar 添加可執(zhí)行權(quán)限
composer腳本拷貝一份到環(huán)境變量目錄下(為了執(zhí)行方便)
cp -a composer.phar /usr/bin/composer

4.集成illuminate database

  • index.php入口文件集成
<?php
#define('APPLICATION_PATH', dirname(__FILE__));
use \Illuminate\Database\Capsule\Manager as Capsule;
// Set the event dispatcher used by Eloquent models... (optional)
use \Illuminate\Events\Dispatcher;
use \Illuminate\Container\Container;

define('APPLICATION_PATH', dirname(__DIR__));

// Autoload 自動(dòng)載入
require '../vendor/autoload.php';
// Eloquent ORM
$capsule = new Capsule;
$capsule->addConnection([
    'driver'    => 'mysql',
    'host'      => '192.168.1.137',
    'database'  => 'sample',
    'username'  => 'root',
    'password'  => '111111',
    'charset'   => 'utf8',
    'collation' => 'utf8_unicode_ci',
    'prefix'    => '',
]);


$capsule->setEventDispatcher(new Dispatcher(new Container));

// Make this Capsule instance available globally via static methods... (optional)
$capsule->setAsGlobal();

// Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
$capsule->bootEloquent();

$application = new Yaf_Application( APPLICATION_PATH . "/conf/application.ini");
$application->bootstrap()->run();
?>

  • \application\Bootstrap.php 引導(dǎo)文件中集成

注意命名空間的使用

<?php
/**
 * @name Bootstrap
 * @author root
 * @desc 所有在Bootstrap類中, 以_init開頭的方法, 都會(huì)被Yaf調(diào)用,
 * @see http://www.php.net/manual/en/class.yaf-bootstrap-abstract.php
 * 這些方法, 都接受一個(gè)參數(shù):Yaf_Dispatcher $dispatcher
 * 調(diào)用的次序, 和申明的次序相同
 */

use \Illuminate\Database\Capsule\Manager as Capsule;
use \Illuminate\Events\Dispatcher;
use \Illuminate\Container\Container;


class Bootstrap extends Yaf_Bootstrap_Abstract{
    protected $config;
    public function _initConfig() {
        //把配置保存起來
        $arrConfig = Yaf_Application::app()->getConfig();
        $this->config = $arrConfig->toArray();
        Yaf_Registry::set('config', $arrConfig);
    }
    /**
     注冊(cè)錯(cuò)誤調(diào)試模式功能
    */
    public function _initError(Yaf_Dispatcher $dispatcher) {
        $config_all = $this->config;

        if ($config_all['application']['debug'])
        {
            define('DEBUG_MODE', false);
            ini_set('display_errors', 'On');
        }
        else
        {
            define('DEBUG_MODE', false);
            ini_set('display_errors', 'Off');
        }
    }

    /**
     * 注冊(cè)composer
     */
    public function _initAutoload(Yaf_Dispatcher $dispatcher) {

        // Autoload 自動(dòng)載入
        require APPLICATION_PATH.'/vendor/autoload.php';

        // Eloquent ORM
        $capsule = new Capsule;
        $capsule->addConnection([
            'driver'    => 'mysql',
            'host'      => '192.168.1.137',
            'database'  => 'sample',
            'username'  => 'root',
            'password'  => '111111',
            'charset'   => 'utf8',
            'collation' => 'utf8_unicode_ci',
            'prefix'    => '',
        ]);

        $capsule->setEventDispatcher(new Dispatcher(new Container));
        // Make this Capsule instance available globally via static methods... (optional)
        $capsule->setAsGlobal();

        // Setup the Eloquent ORM... (optional; unless you've used setEventDispatcher())
        $capsule->bootEloquent();

    }





    public function _initPlugin(Yaf_Dispatcher $dispatcher) {
        //注冊(cè)一個(gè)插件
        //$objSamplePlugin = new SamplePlugin();
        //$dispatcher->registerPlugin($objSamplePlugin);
    }

    public function _initRoute(Yaf_Dispatcher $dispatcher) {
        //在這里注冊(cè)自己的路由協(xié)議,默認(rèn)使用簡(jiǎn)單路由
    }
    
    public function _initView(Yaf_Dispatcher $dispatcher){
        //在這里注冊(cè)自己的view控制器,例如smarty,firekylin
    }


}

具體使用:
Laravel 5.1 LTS 速查表
https://cs.laravel-china.org/

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容