有使用 valet 启动 yii2.0 程序的吗?我该怎么自定义一个驱动?

我使用的是 advance 版,根据文档

cd ~/Users/gpf/.valet/Drivers
vi YiiAdvanceValetDriver.php

//文件内容
<?php

class YiiAdvanceValetDriver extends ValetDriver
{
    /**
     * Determine if the driver serves the request.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return bool
     */
    public function serves($sitePath, $siteName, $uri)
    {
        if (file_exists($sitePath.'/backend/web')) {
            return true;
        }

        return false;
    }

    /**
     * Determine if the incoming request is for a static file.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return string|false
     */
    public function isStaticFile($sitePath, $siteName, $uri)
    {
        if (file_exists($staticFilePath = $sitePath.'/backend/web/'.$uri)) {
            return $staticFilePath;
        }

        return false;
    }

    /**
     * Get the fully resolved path to the application's front controller.
     *
     * @param  string  $sitePath
     * @param  string  $siteName
     * @param  string  $uri
     * @return string
     */
    public function frontControllerPath($sitePath, $siteName, $uri)
    {
        return $sitePath.'/backend/web/index.php';
    }
}

创建了一个驱动配置,然后进入文件路之后执行的link

cd /path/to/app/admin
valet link new.admin

然后浏览器访问 new.admin.dev的时候报的错误是
图片描述

这个我自己的理解是 yii是按照 valet 给出的路径去加载yii 需要的静态文件去了,但是请求路径明显不对啊,这种情况下我该怎么办?

阅读 3.5k
1 个回答

有现成的驱动,不用自己写 https://github.com/incodenz/y...
如果你Yii2的项目的绝对路径是~/sites/gee
来到~/sites/gee/frontend/web 这是Yii2项目默认的前台入口目录,执行 valet link gee
再来到~/sites/gee/backend/web 执行 valet link admin.gee
就可以通过http://gee.test 打开前台,http://admin.gee.test 打开后台

撰写回答
你尚未登录,登录后可以
  • 和开发者交流问题的细节
  • 关注并接收问题和回答的更新提醒
  • 参与内容的编辑和改进,让解决方法与时俱进
推荐问题