如何使用我的插件向 RainLab.Blog 添加帖子?

问题描述

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

解决方法

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

相关问答

Selenium Web驱动程序和Java。元素在(x,y)点处不可单击。其...
Python-如何使用点“。” 访问字典成员?
Java 字符串是不可变的。到底是什么意思?
Java中的“ final”关键字如何工作?(我仍然可以修改对象。...
“loop:”在Java代码中。这是什么,为什么要编译?
java.lang.ClassNotFoundException:sun.jdbc.odbc.JdbcOdbc...