十月CMS路由 [英] October CMS Routing

查看:105
本文介绍了十月CMS路由的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在我的OctoberCMS应用程序中配置路由.我在插件的Plugin.php文件中配置路由. 目前,我的代码:

I'm trying to configure routes in my OctoberCMS app. I configure routes in Plugin.php file of my plugin. At the moment my code:

public function boot()
    {

        Validator::extend('numeric_for_repeater', function($attribute, $value, $parameters) {
            foreach ($value as $v)
            {
                $validator = Validator::make(
                    $v,
                    [
                        'stock_quantity' => 'sometimes|numeric',
                        'stock_votes_quantity' => 'sometimes|numeric',
                        'value' => 'sometimes|numeric',
                    ],
                    $parameters
                );
                if ($validator->fails())
                    return false;
            }
            return true;
        });

        \Route::get('/oferty/{id}', function ($id = null) {

            $theme =  Theme::getActiveTheme();
            $path = \Config::get('cms.themesPath', '/themes').'/'.$theme->getDirName();
            $this->assetPath = $path;
            $offer = new Offer();
        return \View::make(self::MAMF_PAGE_DIR . 'oferta.htm', ['offer' => $offer->getOfferById($id)]);

        });
    }

但是我得到一个错误: View [.var.www.plugins.mamf.mamf2017..........themes.mamf2017.pages.oferta.htm] not found.,因为默认情况下,十月期望插件目录中的视图文件. 我如何在插件目录之外呈现视图,例如在themes路径中,例如app/themes/mamf2017/pages/oferta.htm

but I got an error: View [.var.www.plugins.mamf.mamf2017..........themes.mamf2017.pages.oferta.htm] not found. because by default October expects views files in plugin directory. How can I render view outside of plugin dir, for ex in themes path like this app/themes/mamf2017/pages/oferta.htm

推荐答案

我猜 self :: MAMF_PAGE_DIR 是应用程序的完整基本路径.例如

I guess self::MAMF_PAGE_DIR is full base path your application. for example like

/var/www/vhosts/octdev/themes/responsiv-flat/

简而言之 \ View :: make 需要根目录的绝对路径

In short \View::make need absolute path from root

现在,它将尝试查找具有october-cms的 .htm 扩展名的文件.其他是 .blade .htm.blade 等..

now it will try to look file with configured extensions for october-cms its .htm. others are .blade and .htm.blade etc ..

因此,在您的情况下,(视图)文件名是'oferta.htm'..(点)会转换为'/'路径分隔符,因此请不要使用它,而只需使用 'oferta' ,因此它将检查页面目录中的所有可能值

so in your case (view)file name is 'oferta.htm' that .(dot) is translated to '/' path separator so just don't use it and just use 'oferta' so it will check all possible values in pages directory

  • oferta.htm
  • oferta.blade
  • oferta.htm.balde

添加.htm是自动的,因此您只需提供视图名称,它便会自动查找并工作

this adding .htm is automatic thing so you just need to provide name of view then it will find and work automatically

\Route::get('/oferty/{id}', function ($id = null) {

        $theme =  \Cms\Classes\Theme::getActiveTheme();
        $path = \Config::get('cms.themesPath', '/themes').'/'.$theme->getDirName();
        $this->assetPath = $path;
        $offer = new Offer();
        return \View::make(base_path() . $path . '/pages/' . 'oferta', ['offer' => $offer->getOfferById($id)]);

    });

这已经过测试,希望能对您有所帮助. 如果无法正常工作,请发表评论.

this is tested and working fine hope this will help you. if its not working please comment.

这篇关于十月CMS路由的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆