dtrt2368 2011-09-20 16:22
浏览 41
已采纳

带有subdir的Zend Framework主机名路由

A module of my project should have it's own domain so i created a route for it:

$portalurl = str_replace( 'http://', '', $config->domains->portal );

$hostnameRoute = new Zend_Controller_Router_Route_Hostname(
    $portalurl,
    array( 'module' => 'portal' )
);

$defaultroute = new Zend_Controller_Router_Route(
    ':controller/:action',
    array(
        'controller' => 'index',
        'action' => 'index'
    )
);

$contentroute = new Zend_Controller_Router_Route(
    'page/:page',
    array(
        'controller'=> 'content',
        'action' => 'show'
    )
);

$router->addRoute( 'portalDefault', $hostnameRoute->chain($defaultroute) );
$router->addRoute( 'portalContent', $hostnameRoute->chain($contentroute) );

In my test system my application is in a sub directory like /project/public which works fine when i open the module via the domain i entered in my system host list. domain.lan/project/public. Now i want to assemble a url via the system (redirect) and it assebles it without the sub directory.

$this->_redirect(
    $this->view->url(array(
        'action' => 'index',
        'controller' => 'index')
    ),
    array( 'prependBase' => false )
); 

Yes i know the easiest way to solve it, is to configure a vhost but it bothers me that i can't find another solution wich allows it to function without a vhost and setting the path manually in the routes.

What is the best approach for this?

  • 写回答

2条回答 默认 最新

  • dsndm82062 2011-09-24 19:00
    关注

    Sometimes ZF cannot properly detect the baseUrl (it can't be great at everything...) so we need to set it manually in the bootstrap; you should be able to do this in the .ini, but it did not work for me.

    Note that it is best to put this right at the beginning of the _initView, before anything else:

    protected function _initView()
    {
        // Set the Base URL (only needed sometimes)
        $front = Zend_Controller_Front::getInstance();
        $front->setBaseUrl( '/myapp/public' );
        //initialize view
        $view = new Zend_View...
    

    Then use baseUrl() to wrap your linked files, etc.: $this->baseUrl('css/template.css');

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛