【问题标题】:How can I add a post to RainLab.Blog using my plugin?如何使用我的插件向 RainLab.Blog 添加帖子?
【发布时间】:2021-05-07 20:43:07
【问题描述】:

我想从 RSS 提要中获取信息并将其传输到 RainLab.Blog。 我已经创建了自己的插件 我不明白如何触发 RainLab.Blog 的动作

【问题讨论】:

  • 您可以简单地使用 post modal \plugins\rainlab\blog\models\Post.php => $post = new RainLab\Blog\Models\Post(); 分配所有值并保存。

标签: octobercms octobercms-plugins


【解决方案1】:
$AllCategories = 2; // category id
$post = new Post();
$post->title = 'testSetPost';
$post->slug = 'testSetPost';
$post->content = '<h1>TEST SET POST</h1>';
$post->excerpt = '<h6>TEST SET POST</h6>';
$post->published_at = '2021-02-05 15:14:23';
$post->published = true;
$post->save();

$post->categories()->attach($AllCategories);

$file = new File;
$file->fromUrl('https://picsum.photos/500/320/?random=1','test-set-post' . '.jpg');
        
$post->featured_images()->save($file);

【讨论】:

    猜你喜欢
    • 2021-08-27
    • 2011-12-12
    • 1970-01-01
    • 2016-01-31
    • 2014-06-08
    • 2012-10-02
    • 2023-03-03
    • 2021-10-04
    • 1970-01-01
    相关资源
    最近更新 更多