OctoberCMS新闻列表/详细信息页面

问题描述 投票:0回答:3

对纯HTML / CSS / Javascript / PHP进行编程之后,由于Laravel框架和OctoberCMS看起来结构良好且易于使用/维护,因此我刚刚开始使用称为OctoberCMS的CMS。但是我对如何处理单个详细信息页面或概述页面有些困惑。

例如,以新闻页面为例。到目前为止,我已经创建了此页面:

title = "News"
url = "/news/:news_id?|^[0-9]+$"
layout = "default"
description = "This is the news page."
is_hidden = "0"
meta_title = "News"
meta_description = "News page meta description"
==
<?php
function onStart()
{
    $news_id = $this->param('news_id');
    if(isset($news_id)) {
        $news_article = []; //get the news article by id
        $this['news_article'] = $news_article;
    } else {
        $news = []; //get an array of news articles (last ... articles ordered by datetime desc)
        $this['news'] = $news;
    }
}
?>
==
<div class="container">
    <h1 class="block-title">
        News
    </h1>
    {% if news_article is defined %}
        Article
    {% else %}
        Overview
    {% endif %}
</div>

但是我实际上在哪里为我的新闻文章建立某种图书馆?我已经阅读了有关在新插件中创建新类的内容,但是找不到有关此问题的任何教程或文档,或者我在搜索时使用了错误的术语。有人可以举一个小例子(也许有新闻报道),也可以发布链接以找到教程/文档吗?

php octobercms
3个回答
1
投票

使用插件代替自己编写所有代码更方便。

[Rain lab plugin允许创建,管理,分类,编辑各种文章(包括新闻)。

您可以从该插件获取管理部分并使用您的访问者视图。


1
投票

文档:https://octobercms.com/docs/plugin/registration

如果您想在命令行中生成一些代码,这里是一些有用的命令:

生成插件注册文件和文件夹

php artisan create:plugin AuthorName.PluginName

生成模型

php artisan create:model AuthorName.PluginName ModelName

生成控制器

php artisan create:controller AuthorName.PluginName ModelNames

刷新(重新安装)插件

php artisan plugin:refresh AuthorName.PluginName

这应该可以帮助您,之后文档会有所帮助。


0
投票

使用Builder(https://octobercms.com/plugin/rainlab-builder)插件可以非常轻松地管理CRUD。

假设您有一个名为NewsModel的模型,并且想要在前端显示新闻列表或单个新闻,则可以通过以下方式修改代码。

N.B:无需在php部分中编写php开始和结束标记,只需编写

use Namespace\Plugin\Models\NewsModel; //needed to get data through model
function onStart()
{
    $news_id = $this->param('news_id');
    if($news_id) {
        $news_article = []; //get the news article by id
        $this['news_article'] = $news_article;
    } else {
        $news = []; //get an array of news articles (last ... articles ordered by datetime desc)
        $this['news_list'] = $news;
    }
}
==
<div class="container">    
    {% if news_article %}
        <h1 class="block-title"> News Details</h1>
        <div>{{ news_article.details }}</div> <!--Suppose you have a field named 'details' in the news table -->
    {% elseif news_list %}
        <h1 class="block-title"> News List</h1>
        <ul>
        {% for news in news_list %}
           <li> {{ news.title }}</li><!--Suppose you have a field named 'title' in the news table -->
        {% endfor %}
        </ul>
    {% else %}
        No news found !
    {% endif %}
</div>
© www.soinside.com 2019 - 2024. All rights reserved.