创建 yaf 项目目录及文件(windows)

yaf 项目目录结构

+ public
  |- index.php // 入口文件
  |- .htaccess // 重写规则
  |- composer.json // composer 配置文件
  |+ static
     |- css
     |- img
     |- js
+ conf
  |- application.ini // 项目配置文件   
+ application
  |+ controllers
     |- Index.php // 默认控制器
  |+ views    
     |+ index   // 控制器
        |- index.phtml // 默认视图
  |+ modules // 其他模块
  |+ library // 本地类库
  |+ models  // model目录
  |+ plugins // 插件目录

入口文件:public/index.php

bootstrap()->run();

apache 重写规则文件:public/.htaccess

RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule .* index.php

apache 虚拟主机配置

  • 项目根目录路径为:E:/Project/hyso/yaf,Directory 配置项为项目根目录下的 public 目录(index.php 文件所在目录)
  • 虚拟主机域名:local-yaf.bmtrip.com,本地 hosts 文件相应加上此域名的配置

    ServerAdmin [email protected]
    DocumentRoot "E:/Project/hyso/yaf/public"
    ServerName local-yaf.bmtrip.com
      
        Options FollowSymLinks Includes ExecCGI
        AllowOverride All 
        Require all granted  
      
    ErrorLog "logs/local-yaf.bmtrip.com-error.log"
    CustomLog "logs/local-yaf.bmtrip.com-access.log" common

composer 配置文件:public/composer.json

{
    "config": {
        "vendor-dir": "../vendor"
    }
}

处理 composer 依赖关系

运行命令行窗口,切换到项目根目录,执行以下命令:

composer install

默认控制器文件:application/controllers/Index.php

getView()->assign("content", "Hello World");
   }

   /**
    * test Action
    * 
    */
   public function testAction()
   {
       $this->getView()->assign("content", "test");

       $this->getView()->display('index/index.phtml');

       return false;
   }
}

项目配置文件:conf/application.ini

[common]
application.directory = APP_PATH "/application/" 
application.bootstrap = APP_PATH "/application/Bootstrap.php" 

[product:common]

Bootstrap 文件:application/Bootstrap.php

getConfig();

        Yaf_Registry::set("config", $config);
    }

    public function _initDefaultUrl(Yaf_Dispatcher $dispatcher)
    {
        $dispatcher
        ->setDefaultModule("Index")
        ->setDefaultController("Index")
        ->setDefaultAction("test");
    }

    public function _initAutoload()
    {
        require '../vendor/autoload.php';
    }
}

默认视图文件:application/views/index/index.phtml

  • 视图文件目录:application/views
  • 默认控制器视图文件目录(目录名与控制器文件名保持一致):application/views/index

    
        Hello World
    
    
        
    

浏览器中访问控制器

  • http://www.yourhostname.com/index.php
  • http:///www.yourhostname.com/index/index/index
  • http:///www.yourhostname.com/index/index/test

你可能感兴趣的:(创建 yaf 项目目录及文件(windows))