如何从另一个支持的页面表单调用值并将其用于 OctoberCms 中的组件
How do I call the value from another backed page form and use it on a component in OctoberCms
我正在制作一个 seo 插件,我也在使用 rainlab 博客插件,我创建了一个带有字段的选项卡,我可以在其中输入我想包含在页面的 head 标签中的元数据,但是我不知道如何从博客区域(rainlab 插件菜单选项卡)中的表单字段中调用值,而我的 seo 组件位于 cms 页面我尝试使用 {{this.page.variable}}'方法,但由于输入表单位于另一个后端页面,因此它不起作用。
这是我的 plugin.php 的样子:
<?php namespace Stronganswer\Seo;
use Backend;
use Event;
use System\Classes\PluginBase;
use Cms\Classes\Page;
use Cms\Classes\Theme;
use System\Classes\PluginManager;
use System\Classes\SettingsManager;
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'seo',
'description' => 'meta and og tag handler',
'author' => 'stronganswer',
'icon' => 'icon-leaf'
];
}
/**
* Registers any front-end components implemented in this plugin.
*
* @return array
*/
public function registerComponents()
{
return [
'Stronganswer\Seo\Components\Seo' => 'seoHandler',
'Stronganswer\Seo\Components\BlogPost' => 'SeoBlogPost',
'Stronganswer\Seo\Components\StaticPage' => 'SeoStaticPage',
'Stronganswer\Seo\Components\CmsPage' => 'SeoCmsPage',
];
}
public function registerSettings(){
return [
'settings' => [
'label' => 'SEO Settings',
'description' => 'Seo Settings.',
'icon' => 'icon-bar-chart-o',
'class' => 'stronganswer\seo\Models\settings',
'context' => 'mysettings',
'category' => SettingsManager::CATEGORY_MYSETTINGS,
'order' => 1
]
];
}
/**
* Registers any back-end permissions used by this plugin.
*
* @return array
*/
public function registerPermissions()
{
return [
'stronganswer.seo.some_permission' => [
'tab' => 'seo',
'label' => 'Some permission'
],
];
}
/**
* Registers back-end navigation items for this plugin.
*
* @return array
*/
/* public function registerNavigation()
{
return [
'seo' => [
'label' => 'seo',
'url' => Backend::url('stronganswer/seo/controllers'),
'icon' => 'icon-leaf',
'permissions' => ['stronganswer.seo.*'],
'order' => 500,
],
];
}*/
public function boot()
{
Event::listen('backend.form.extendFields', function($widget)
{
if(PluginManager::instance()->hasPlugin('RainLab.Pages') && $widget->model instanceof \RainLab\Pages\Classes\Page)
{ //static pages fields
$widget->addFields([
'viewBag[seo_title]' =>[
'label' => 'Meta Title',
'tab' => 'SEO',
'type' => 'text'
],
'viewBag[seo_description]' =>[
'label' => 'Meta Description',
'tab' => 'SEO',
'size' => 'tiny',
'type' => 'textarea'
],
'viewBag[seo_keywords]' =>[
'label' => 'Meta Keywords',
'tab' => 'SEO',
'type' => 'text'
],
'viewBag[robot_index]' => [
'label' => 'Robot Index',
'type' => 'dropdown',
'tab' => 'SEO',
'options' => ["index"=>"index","noindex"=>"noindex"],
'default' => 'index',
'span' => 'left'
],
'viewBag[robot_follow]' => [
'label' => 'Robot Follow',
'type' => 'dropdown',
'tab' => 'SEO',
'options' => ["follow"=>"follow","nofollow"=>"nofollow"],
'default' => 'follow',
'span' => 'right'
]
], 'primary');
}
if(PluginManager::instance()->hasPlugin('RainLab.Blog') && $widget->model instanceof \RainLab\Blog\Models\Post)
{
$widget->addFields([
'blog_title' =>[
'label' => 'Meta Title',
'tab' => 'Blog Seo',
'type' => 'text'
],
'seo_description' =>[
'label' => 'Meta Description',
'tab' => 'Blog Seo',
'size' => 'tiny',
'type' => 'textarea'
],
'seo_keywords' =>[
'label' => 'Meta Keywords',
'tab' => 'Blog Seo',
'type' => 'text'
],
'robot_index' => [
'label' => 'Robot Index',
'type' => 'dropdown',
'tab' => 'Blog Seo',
'options' => ["index"=>"index","noindex"=>"noindex"],
'default' => 'index',
'span' => 'left'
],
'canonical_url' => [
'label' => 'Canonical URL',
'type' => 'text',
'tab' => 'SEO',
'span' => 'left'
],
'robot_follow' => [
'label' => 'Robot Follow',
'type' => 'dropdown',
'tab' => 'Blog Seo',
'options' => ["follow"=>"follow","nofollow"=>"nofollow"],
'default' => 'follow',
'span' => 'right'
]
], 'secondary');
}
if (!$widget->model instanceof \Cms\Classes\Page) return;
//cms page fields
$widget->addFields([
'settings[seo_title]' =>[
'label' => 'Meta Title',
'tab' => 'SEO',
'type' => 'text'
],
'settings[seo_description]' =>[
'label' => 'Meta Description',
'tab' => 'SEO',
'size' => 'tiny',
'type' => 'textarea'
],
'settings[seo_keywords]' =>[
'label' => 'Meta Keywords',
'tab' => 'SEO',
'type' => 'text'
],
'settings[robot_index]' => [
'label' => 'Robot Index',
'type' => 'dropdown',
'tab' => 'SEO',
'options' => ["index"=>"index","noindex"=>"noindex"],
'default' => 'index',
'span' => 'left'
],
'settings[robot_follow]' => [
'label' => 'Robot Follow',
'type' => 'dropdown',
'tab' => 'SEO',
'options' => ["follow"=>"follow","nofollow"=>"nofollow"],
'default' => 'follow',
'span' => 'right'
]
], 'primary');
});
}
}
这是我的组件:
<?php namespace Stronganswer\Seo\Components;
use DB;
use Cms\Classes\ComponentBase;
use Stronganswer\Seo\models\Settings;
use RainLab\Pages\Classes\Router;
use RainLab\Blog\Models\Post;
use Cms\Classes\Theme;
use Cms\Classes\Page;
use Request;
use Event;
class BlogPost extends ComponentBase
{
//singular page tags
public $page;
public $blog_title;
public $seo_title;
public $seo_description;
public $seo_keywords;
public $robot_index;
public $robot_follow;
//global tags
public $ogTitle;
public $ogDescription;
public $ogSiteName;
public $ogUrl;
public $ogType;
public $ogAuthor;
public $ogImage;
//facebook tags
public $ogFbAppId;
public $ogFbAdmins;
//google tags
public $ogGlTitle;
public $ogGlDescription;
public $ogGlImage;
//twitter tags
public $ogTtCard;
public $ogTtSite;
public $ogTtTitle;
public $ogTtDescription;
public $ogTtAuthor;
public $ogTtImage;
public function componentDetails()
{
return [
'name' => 'Seo BlogPost component',
'description' => 'handles seo fields into blogposts'
];
}
public function defineProperties()
{
return [
"post" => [
"title" => "data",
"default" => "post"
]
];
}
public function Run()
{
$theme = Theme::getActiveTheme();
$page = Page::load($theme,$this->page->baseFileName);
$this->page["hasBlog"] = true;
if($page->hasComponent("blogPost"))
{
//$seo = DB::table('rainlab_blog_posts')->get();
//$blog_title = DB::table('rainlab_blog_posts')->where('slug','=','first-blog-post')->value('seo_title');
//$this->seo_title = $this->page['blog_title'] = $this->page->getViewBag()->property('blog_title');
//$this->seo_title = $this->page["seo_title"] = $this->page->seo_title;
/*$blog_title = DB::table('rainlab_blog_posts')
->select(DB::raw('select seo_title'))
->where('slug', '=', 'first-blog-post')
->get();*/
$this->seo_description = $this->page["seo_description"] = $this->page->meta_description;
$this->seo_keywords = $this->page["seo_keywords"] = $this->page->seo_keywords;
$this->robot_follow = $this->page["robot_follow"] = $this->page->robot_follow;
$this->robot_index = $this->page["robot_index"] = $this->page->robot_index;
$settings = Settings::instance();
if($settings->enable_og_tags)
{
$this->ogTitle = $settings->og_title;
$this->ogDescription = $settings->og_description;
$this->ogSiteName = $settings->og_sitename;
$this->ogUrl = $settings->og_url;
$this->ogType = $settings->og_type;
$this->ogAuthor = $settings->og_author;
$this->ogImage = $settings->og_img;
}
if($settings->enable_fb_tags)
{
$this->ogFbAppId = $settings->og_fb_appid;
$this->ogFbAdmins = $settings->og_fb_admins;
}
if($settings->enable_ggl_tags)
{
$this->ogGlTitle = $settings->og_gl_title;
$this->ogGlDescription = $settings->og_gl_description;
$this->ogGlImage = $settings->og_gl_img;
}
if($settings->enable_tt_tags)
{
$this->ogTtCard = $settings->og_tt_card;
$this->ogTtSite = $settings->og_tt_site;
$this->ogTtTitle = $settings->og_tt_title;
$this->ogTtDescription = $settings->og_tt_description;
$this->ogTtAuthor = $settings->og_tt_author;
$this->ogTtImage = $settings->og_tt_img;
}
}
else{
$this->hasBlog = $this->page["hasBlog"] = false;
}
}
}
注释中的代码尝试从表单中获取值失败。如果我转到我的数据库,我可以看到我在表单中输入的值,但我无法将它们调用到我的组件中。
和我的 deafult.htm :
<meta name="title" content="{{__SELF__.blog_title}}">
<meta name="description" content="{{__SELF__.seo_description}}">
<meta name="keywords" content="{{__SELF__.seo_keywords}}">
<meta name="robots" content="{{__SELF__.robot_index}},{{__SELF__.robot_follow}}">
<meta property="og:site_name" content="{{ __SELF__.ogSiteName }}" />
<meta property="og:title" content="{{ __SELF__.ogTitle }}" />
<meta property="og:url" content="{{ __SELF__.ogUrl }}" />
<meta property="og:description" content="{{ __SELF__.ogDescription }}" />
<meta property="og:type" content="{{ __SELF__.ogType }}" />
<meta name="author" content="{{ __SELF__.ogAuthor }}" />
<meta property="og:image" content="{{ __SELF__.ogImage }}" />
<meta property="fb:app_id" content="{{ __SELF__.ogFbAppId }}" />
<meta property="fb:admins" content="{{ __SELF__.ogFbAdmins }}" />
<meta itemprop="name" content="{{ __SELF__.ogGlTitle }}" />
<meta itemprop="description" content="{{ __SELF__.ogGlDescription }}" />
<meta itemprop="image" content="{{ __SELF__.ogGlImage }}" />
<meta itemprop="image" content="{{ __SELF__.ogGlImage }}" />
<meta name="twitter:card" content="{{__SELF__.ogTtCard}}">
<meta name="twitter:site" content="{{__SELF__.ogTtSite}}">
<meta name="twitter:title" content="{{__SELF__.ogTtTitle}}">
<meta name="twitter:description" content="{{__SELF__.ogTtDescription}}">
<meta name="twitter:creator" content="{{__SELF__.ogTtAuthor}}">
<meta name="twitter:image:src" content="{{__SELF__.ogTtImage}}">
我也有用于 cms 页面和 rainlab 页面插件(静态页面)的表单,我从我制作的另一个组件中获取它们,我想指出它们都工作正常。
如果您需要表单中的值,请使用 Input
class
https://octobercms.com/docs/services/request-input
You may access all user input with a few simple methods. You do not need to worry about the HTTP verb for the request when using the Input facade, as input is accessed in the same way for all verbs. The global input() helper function is an alias for Input::get.
Retrieving an input value
$name = Input::get('name');
Retrieving a default value if the input value is absent
$name = Input::get('name', 'Sally');
Determining if an input value is present
if (Input::has('name')) {
//
}
但我认为你的意思是别的,但我不确定,因为实际问题还不清楚。
扩展插件时需要考虑很多事情,在这些情况下您应该检查:
- 我的字段是否在数据库中创建?
- 我的值会保存在数据库中吗?
- 我应该在这些项目上使用关系而不是修改这些项目
- 我可以
dd($somevalue)
我的组件中的值吗(dd 终止任何执行并转储变量。对分析它们非常有用)
- 我是否有单独的管理模型和控制器来管理我的值以进行调试。这些显示了什么?
- 我可以通过查询直接访问这些值吗?
- 我的组件设置 configured/registered 正确吗?
- Settings/Event 日志中跟踪了哪些错误
开始时调试 october 可能会很痛苦,但是一旦掌握了它就会很有趣:-)
要从数据库中调用值,我是这样做的:
将其插入到组件 onRun 函数中:
$this->blog_seo_or_smth = DB::table('rainlab_blog_posts')->where('slug','first-blog-post')->first();
然后在 default.htm:
<meta name="title" content="{{__SELF__.blog_seo_or_smth.seo_title}}">
我也在努力了解如何同时扩展 cmsPages 和 rainlabPages 中的字段,然后使用部分打印我的 html 源中的字段。
所以我创建了这个部分:
<meta charset="utf-8" >
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="{{ this.page.meta_description }}">
<meta name="robots" content=",">
<meta property="og:title" content="October - {{ this.page.title }}" />
<meta property="og:url" content="{{ this.page.url }}" />
<meta property="og:site_name" content="{{ title }}" />
<meta property="og:description" content="{{ this.page.meta_description }}" />
<meta property="fb:app_id" content="xxx" />
<meta property="og:type" content="xxx">
<meta property="og:image" content="{{ this.theme.site_logo_url }}">
<meta name="twitter:card" content="{{ summary }}">
<meta name="twitter:title" content="October- {{ this.page.title }}">
<meta name="twitter:description" content="{{ this.page.meta_description }}">
<meta name="twitter:image" content="{{ this.theme.site_logo_url }}">
我认为最好的解决方案是:创建一个扩展 cmsPages 和 rainLab 页面字段的插件,而不是使用部分打印!
查看 anandpatel 的 seoextension 代码可能会有所帮助,但我的编码能力不是很强,所以我们可以互相帮助。
我认为函数是:
public function register()
{
\Event::listen('backend.form.extendFields', function($widget)
{
if(PluginManager::instance()->hasPlugin('RainLab.Pages') && $widget->model instanceof \RainLab\Pages\Classes\Page)
{
if (!$widget->model instanceof \Cms\Classes\Page) return;
if (!($theme = Theme::getEditTheme())) {
throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found'));
也许我们可以将这个项目插入到 git。
再见
加布里埃尔
我正在制作一个 seo 插件,我也在使用 rainlab 博客插件,我创建了一个带有字段的选项卡,我可以在其中输入我想包含在页面的 head 标签中的元数据,但是我不知道如何从博客区域(rainlab 插件菜单选项卡)中的表单字段中调用值,而我的 seo 组件位于 cms 页面我尝试使用 {{this.page.variable}}'方法,但由于输入表单位于另一个后端页面,因此它不起作用。
这是我的 plugin.php 的样子:
<?php namespace Stronganswer\Seo;
use Backend;
use Event;
use System\Classes\PluginBase;
use Cms\Classes\Page;
use Cms\Classes\Theme;
use System\Classes\PluginManager;
use System\Classes\SettingsManager;
class Plugin extends PluginBase
{
/**
* Returns information about this plugin.
*
* @return array
*/
public function pluginDetails()
{
return [
'name' => 'seo',
'description' => 'meta and og tag handler',
'author' => 'stronganswer',
'icon' => 'icon-leaf'
];
}
/**
* Registers any front-end components implemented in this plugin.
*
* @return array
*/
public function registerComponents()
{
return [
'Stronganswer\Seo\Components\Seo' => 'seoHandler',
'Stronganswer\Seo\Components\BlogPost' => 'SeoBlogPost',
'Stronganswer\Seo\Components\StaticPage' => 'SeoStaticPage',
'Stronganswer\Seo\Components\CmsPage' => 'SeoCmsPage',
];
}
public function registerSettings(){
return [
'settings' => [
'label' => 'SEO Settings',
'description' => 'Seo Settings.',
'icon' => 'icon-bar-chart-o',
'class' => 'stronganswer\seo\Models\settings',
'context' => 'mysettings',
'category' => SettingsManager::CATEGORY_MYSETTINGS,
'order' => 1
]
];
}
/**
* Registers any back-end permissions used by this plugin.
*
* @return array
*/
public function registerPermissions()
{
return [
'stronganswer.seo.some_permission' => [
'tab' => 'seo',
'label' => 'Some permission'
],
];
}
/**
* Registers back-end navigation items for this plugin.
*
* @return array
*/
/* public function registerNavigation()
{
return [
'seo' => [
'label' => 'seo',
'url' => Backend::url('stronganswer/seo/controllers'),
'icon' => 'icon-leaf',
'permissions' => ['stronganswer.seo.*'],
'order' => 500,
],
];
}*/
public function boot()
{
Event::listen('backend.form.extendFields', function($widget)
{
if(PluginManager::instance()->hasPlugin('RainLab.Pages') && $widget->model instanceof \RainLab\Pages\Classes\Page)
{ //static pages fields
$widget->addFields([
'viewBag[seo_title]' =>[
'label' => 'Meta Title',
'tab' => 'SEO',
'type' => 'text'
],
'viewBag[seo_description]' =>[
'label' => 'Meta Description',
'tab' => 'SEO',
'size' => 'tiny',
'type' => 'textarea'
],
'viewBag[seo_keywords]' =>[
'label' => 'Meta Keywords',
'tab' => 'SEO',
'type' => 'text'
],
'viewBag[robot_index]' => [
'label' => 'Robot Index',
'type' => 'dropdown',
'tab' => 'SEO',
'options' => ["index"=>"index","noindex"=>"noindex"],
'default' => 'index',
'span' => 'left'
],
'viewBag[robot_follow]' => [
'label' => 'Robot Follow',
'type' => 'dropdown',
'tab' => 'SEO',
'options' => ["follow"=>"follow","nofollow"=>"nofollow"],
'default' => 'follow',
'span' => 'right'
]
], 'primary');
}
if(PluginManager::instance()->hasPlugin('RainLab.Blog') && $widget->model instanceof \RainLab\Blog\Models\Post)
{
$widget->addFields([
'blog_title' =>[
'label' => 'Meta Title',
'tab' => 'Blog Seo',
'type' => 'text'
],
'seo_description' =>[
'label' => 'Meta Description',
'tab' => 'Blog Seo',
'size' => 'tiny',
'type' => 'textarea'
],
'seo_keywords' =>[
'label' => 'Meta Keywords',
'tab' => 'Blog Seo',
'type' => 'text'
],
'robot_index' => [
'label' => 'Robot Index',
'type' => 'dropdown',
'tab' => 'Blog Seo',
'options' => ["index"=>"index","noindex"=>"noindex"],
'default' => 'index',
'span' => 'left'
],
'canonical_url' => [
'label' => 'Canonical URL',
'type' => 'text',
'tab' => 'SEO',
'span' => 'left'
],
'robot_follow' => [
'label' => 'Robot Follow',
'type' => 'dropdown',
'tab' => 'Blog Seo',
'options' => ["follow"=>"follow","nofollow"=>"nofollow"],
'default' => 'follow',
'span' => 'right'
]
], 'secondary');
}
if (!$widget->model instanceof \Cms\Classes\Page) return;
//cms page fields
$widget->addFields([
'settings[seo_title]' =>[
'label' => 'Meta Title',
'tab' => 'SEO',
'type' => 'text'
],
'settings[seo_description]' =>[
'label' => 'Meta Description',
'tab' => 'SEO',
'size' => 'tiny',
'type' => 'textarea'
],
'settings[seo_keywords]' =>[
'label' => 'Meta Keywords',
'tab' => 'SEO',
'type' => 'text'
],
'settings[robot_index]' => [
'label' => 'Robot Index',
'type' => 'dropdown',
'tab' => 'SEO',
'options' => ["index"=>"index","noindex"=>"noindex"],
'default' => 'index',
'span' => 'left'
],
'settings[robot_follow]' => [
'label' => 'Robot Follow',
'type' => 'dropdown',
'tab' => 'SEO',
'options' => ["follow"=>"follow","nofollow"=>"nofollow"],
'default' => 'follow',
'span' => 'right'
]
], 'primary');
});
}
}
这是我的组件:
<?php namespace Stronganswer\Seo\Components;
use DB;
use Cms\Classes\ComponentBase;
use Stronganswer\Seo\models\Settings;
use RainLab\Pages\Classes\Router;
use RainLab\Blog\Models\Post;
use Cms\Classes\Theme;
use Cms\Classes\Page;
use Request;
use Event;
class BlogPost extends ComponentBase
{
//singular page tags
public $page;
public $blog_title;
public $seo_title;
public $seo_description;
public $seo_keywords;
public $robot_index;
public $robot_follow;
//global tags
public $ogTitle;
public $ogDescription;
public $ogSiteName;
public $ogUrl;
public $ogType;
public $ogAuthor;
public $ogImage;
//facebook tags
public $ogFbAppId;
public $ogFbAdmins;
//google tags
public $ogGlTitle;
public $ogGlDescription;
public $ogGlImage;
//twitter tags
public $ogTtCard;
public $ogTtSite;
public $ogTtTitle;
public $ogTtDescription;
public $ogTtAuthor;
public $ogTtImage;
public function componentDetails()
{
return [
'name' => 'Seo BlogPost component',
'description' => 'handles seo fields into blogposts'
];
}
public function defineProperties()
{
return [
"post" => [
"title" => "data",
"default" => "post"
]
];
}
public function Run()
{
$theme = Theme::getActiveTheme();
$page = Page::load($theme,$this->page->baseFileName);
$this->page["hasBlog"] = true;
if($page->hasComponent("blogPost"))
{
//$seo = DB::table('rainlab_blog_posts')->get();
//$blog_title = DB::table('rainlab_blog_posts')->where('slug','=','first-blog-post')->value('seo_title');
//$this->seo_title = $this->page['blog_title'] = $this->page->getViewBag()->property('blog_title');
//$this->seo_title = $this->page["seo_title"] = $this->page->seo_title;
/*$blog_title = DB::table('rainlab_blog_posts')
->select(DB::raw('select seo_title'))
->where('slug', '=', 'first-blog-post')
->get();*/
$this->seo_description = $this->page["seo_description"] = $this->page->meta_description;
$this->seo_keywords = $this->page["seo_keywords"] = $this->page->seo_keywords;
$this->robot_follow = $this->page["robot_follow"] = $this->page->robot_follow;
$this->robot_index = $this->page["robot_index"] = $this->page->robot_index;
$settings = Settings::instance();
if($settings->enable_og_tags)
{
$this->ogTitle = $settings->og_title;
$this->ogDescription = $settings->og_description;
$this->ogSiteName = $settings->og_sitename;
$this->ogUrl = $settings->og_url;
$this->ogType = $settings->og_type;
$this->ogAuthor = $settings->og_author;
$this->ogImage = $settings->og_img;
}
if($settings->enable_fb_tags)
{
$this->ogFbAppId = $settings->og_fb_appid;
$this->ogFbAdmins = $settings->og_fb_admins;
}
if($settings->enable_ggl_tags)
{
$this->ogGlTitle = $settings->og_gl_title;
$this->ogGlDescription = $settings->og_gl_description;
$this->ogGlImage = $settings->og_gl_img;
}
if($settings->enable_tt_tags)
{
$this->ogTtCard = $settings->og_tt_card;
$this->ogTtSite = $settings->og_tt_site;
$this->ogTtTitle = $settings->og_tt_title;
$this->ogTtDescription = $settings->og_tt_description;
$this->ogTtAuthor = $settings->og_tt_author;
$this->ogTtImage = $settings->og_tt_img;
}
}
else{
$this->hasBlog = $this->page["hasBlog"] = false;
}
}
}
注释中的代码尝试从表单中获取值失败。如果我转到我的数据库,我可以看到我在表单中输入的值,但我无法将它们调用到我的组件中。
和我的 deafult.htm :
<meta name="title" content="{{__SELF__.blog_title}}">
<meta name="description" content="{{__SELF__.seo_description}}">
<meta name="keywords" content="{{__SELF__.seo_keywords}}">
<meta name="robots" content="{{__SELF__.robot_index}},{{__SELF__.robot_follow}}">
<meta property="og:site_name" content="{{ __SELF__.ogSiteName }}" />
<meta property="og:title" content="{{ __SELF__.ogTitle }}" />
<meta property="og:url" content="{{ __SELF__.ogUrl }}" />
<meta property="og:description" content="{{ __SELF__.ogDescription }}" />
<meta property="og:type" content="{{ __SELF__.ogType }}" />
<meta name="author" content="{{ __SELF__.ogAuthor }}" />
<meta property="og:image" content="{{ __SELF__.ogImage }}" />
<meta property="fb:app_id" content="{{ __SELF__.ogFbAppId }}" />
<meta property="fb:admins" content="{{ __SELF__.ogFbAdmins }}" />
<meta itemprop="name" content="{{ __SELF__.ogGlTitle }}" />
<meta itemprop="description" content="{{ __SELF__.ogGlDescription }}" />
<meta itemprop="image" content="{{ __SELF__.ogGlImage }}" />
<meta itemprop="image" content="{{ __SELF__.ogGlImage }}" />
<meta name="twitter:card" content="{{__SELF__.ogTtCard}}">
<meta name="twitter:site" content="{{__SELF__.ogTtSite}}">
<meta name="twitter:title" content="{{__SELF__.ogTtTitle}}">
<meta name="twitter:description" content="{{__SELF__.ogTtDescription}}">
<meta name="twitter:creator" content="{{__SELF__.ogTtAuthor}}">
<meta name="twitter:image:src" content="{{__SELF__.ogTtImage}}">
我也有用于 cms 页面和 rainlab 页面插件(静态页面)的表单,我从我制作的另一个组件中获取它们,我想指出它们都工作正常。
如果您需要表单中的值,请使用 Input
class
https://octobercms.com/docs/services/request-input
You may access all user input with a few simple methods. You do not need to worry about the HTTP verb for the request when using the Input facade, as input is accessed in the same way for all verbs. The global input() helper function is an alias for Input::get.
Retrieving an input value
$name = Input::get('name');
Retrieving a default value if the input value is absent
$name = Input::get('name', 'Sally');
Determining if an input value is present
if (Input::has('name')) {
//
}
但我认为你的意思是别的,但我不确定,因为实际问题还不清楚。
扩展插件时需要考虑很多事情,在这些情况下您应该检查:
- 我的字段是否在数据库中创建?
- 我的值会保存在数据库中吗?
- 我应该在这些项目上使用关系而不是修改这些项目
- 我可以
dd($somevalue)
我的组件中的值吗(dd 终止任何执行并转储变量。对分析它们非常有用) - 我是否有单独的管理模型和控制器来管理我的值以进行调试。这些显示了什么?
- 我可以通过查询直接访问这些值吗?
- 我的组件设置 configured/registered 正确吗?
- Settings/Event 日志中跟踪了哪些错误
开始时调试 october 可能会很痛苦,但是一旦掌握了它就会很有趣:-)
要从数据库中调用值,我是这样做的:
将其插入到组件 onRun 函数中:
$this->blog_seo_or_smth = DB::table('rainlab_blog_posts')->where('slug','first-blog-post')->first();
然后在 default.htm:
<meta name="title" content="{{__SELF__.blog_seo_or_smth.seo_title}}">
我也在努力了解如何同时扩展 cmsPages 和 rainlabPages 中的字段,然后使用部分打印我的 html 源中的字段。 所以我创建了这个部分:
<meta charset="utf-8" >
<meta http-equiv="X-UA-Compatible" content="IE=edge" >
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="description" content="{{ this.page.meta_description }}">
<meta name="robots" content=",">
<meta property="og:title" content="October - {{ this.page.title }}" />
<meta property="og:url" content="{{ this.page.url }}" />
<meta property="og:site_name" content="{{ title }}" />
<meta property="og:description" content="{{ this.page.meta_description }}" />
<meta property="fb:app_id" content="xxx" />
<meta property="og:type" content="xxx">
<meta property="og:image" content="{{ this.theme.site_logo_url }}">
<meta name="twitter:card" content="{{ summary }}">
<meta name="twitter:title" content="October- {{ this.page.title }}">
<meta name="twitter:description" content="{{ this.page.meta_description }}">
<meta name="twitter:image" content="{{ this.theme.site_logo_url }}">
我认为最好的解决方案是:创建一个扩展 cmsPages 和 rainLab 页面字段的插件,而不是使用部分打印! 查看 anandpatel 的 seoextension 代码可能会有所帮助,但我的编码能力不是很强,所以我们可以互相帮助。
我认为函数是:
public function register()
{
\Event::listen('backend.form.extendFields', function($widget)
{
if(PluginManager::instance()->hasPlugin('RainLab.Pages') && $widget->model instanceof \RainLab\Pages\Classes\Page)
{
if (!$widget->model instanceof \Cms\Classes\Page) return;
if (!($theme = Theme::getEditTheme())) {
throw new ApplicationException(Lang::get('cms::lang.theme.edit.not_found'));
也许我们可以将这个项目插入到 git。
再见 加布里埃尔