前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
工具
TVP
发布
社区首页 >专栏 >[php]yaf框架熟悉

[php]yaf框架熟悉

作者头像
杨肆月
发布2021-01-26 16:19:36
7210
发布2021-01-26 16:19:36
举报
文章被收录于专栏:全栈开发之路全栈开发之路

一、目录结构

1、入口文件 —— index.php

使用conf中的配置文件application.ini(取目录/application) 调用/application/Bootstrap.php,把这个项目跑起来

代码语言:javascript
复制
<?php

define('APPLICATION_PATH', dirname(__FILE__));
define('APP_PATH', dirname(__FILE__) . '/');
define('FILE_UPLOAD_PATH', dirname(__FILE__) . '/static/uploadDir');

$application = new Yaf_Application( APPLICATION_PATH . "/conf/application.ini");

$application->bootstrap()->run();
?>

2、开发入口 —— Bootstrap.php

很多基础功能都是在这里先注册的

代码语言:javascript
复制
class Bootstrap extends Yaf_Bootstrap_Abstract{

    public function _initConfig() {
        //把配置保存起来
        $arrConfig = Yaf_Application::app()->getConfig();
        Yaf_Registry::set('config', $arrConfig);
    }

    public function _initPlugin(Yaf_Dispatcher $dispatcher) {
        //注册一个插件
        $objSamplePlugin = new PluginMain();
        $dispatcher->registerPlugin($objSamplePlugin);
    }

    public function _initRoute(Yaf_Dispatcher $dispatcher) {
        //在这里注册自己的路由协议,默认使用简单路由
        /* $router = Yaf_Dispatcher::getInstance()->getRouter(); */
        /* $router->addConfig(Yaf_Registry::get("config")->routes); */
    }
    
    public function _initView(Yaf_Dispatcher $dispatcher){
        //在这里注册自己的view控制器,例如smarty,firekylin
    }
}

3、流程

1)index.php 里 加载conf中的文件 2)调用Bootstrap.php 3)根据请求里的controller和action的定义找到对应的controller

4、yaf的路由

rewrite规则

参考: https://www.cnblogs.com/lzzxm/articles/12537379.html https://zhuanlan.zhihu.com/p/341479817

本文参与 腾讯云自媒体分享计划,分享自作者个人站点/博客。
如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体分享计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • 一、目录结构
    • 1、入口文件 —— index.php
      • 2、开发入口 —— Bootstrap.php
        • 3、流程
          • 4、yaf的路由
          领券
          问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档