October CMS Routing

社会主义新天地 提交于 2019-12-12 04:46:34

问题


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)]);

        });
    }

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


回答1:


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

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

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

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

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

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.



来源:https://stackoverflow.com/questions/47177428/october-cms-routing

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!