Development

sfSimpleNewsPlugin

You must first sign up to be able to contribute.

sfSimpleNewsPlugin

Overview

sfSimpleNewsPlugin is a Symfony plugin. It allows you to manage news in your web site with a few clicks.

The news structure is very easy, as you can see from the database: every news has a title, an intro and the body (of course also the is_published flag is there). This plugin has a backend administration through the admin generator, and a few helpers for your templates:

  • The latest_news helper shows a list of the latest news;
  • The show_news helper shows a single news;
  • The news_archive helper shows the full archive.

Requirements

The prerequisites for using the sfSimpleNews plugin are:

  • As the plugin doesn't contain a user management module, the project where you install it must have a table managing authors, or users (whatever the name), and the related Propel class must have a __toString() method. Both these conditions are satisfied by the sfGuardPlugin, so installing this plugin is a good choice.

Installation

You can install sfSimpleNewsPlugin via PEAR (recommended) package manager or manually.

PEAR installation

  1. The easiest way to install sfSimpleNewsPlugin is to use PEAR package manager.
 $ symfony plugin-install http://plugins.symfony-project.com/sfSimpleNewsPlugin

Alternatively, if you don't have PEAR installed, you can download the latest package attached to this plugin's wiki page and extract it under your project's plugins/ directory. You will also have to copy the contents of the myproject/plugins/sfSimpleNewsPlugin/web/ directory into a myproject/web/sfSimpleNewsPlugin/ directory.

  1. Now clear the cache with symfony clear-cache command to enable the autoloading to find the new classes:
 $ symfony cc
  1. Copy the sample configuration file from myproject/plugins/sfSimpleNewsPlugin/config/sfNews.yml.sample into yout project's (not application!) config/ folder. Rename it to myproject/config/sfNews.yml. If you want to specify the name of the existing user table and class, edit this file (see next section about the plugin configuration).
 $ symfony propel-build-model
  1. If you use symfony 1.0, you must manually register a config handler for this configuration file by creating a config_handlers.yml file in your application config/ directory with the following content:
 config/sfNews.yml:
  class: sfYamlToSfConfigConfigHandler
  param:
    prefix: sf_simple_news_

This last step is not required if you use symfony 1.1.

  1. Optionally load test data
 $ symfony propel-load-data plugins/sfSimpleNewsPlugin/data/fixtures/test_data.yml
  1. Enable the sfSimpleNewsAdmin module in your backend application, via the settings.yml file.
 // in myproject/apps/backend/config/settings.yml
 all:
  .settings:
    enabled_modules:        [default, sfSimpleNewsAdmin]

You can now use the plugin browsing to the backend module's page:

 http://myproject/backend_dev.php/sfSimpleNewsAdmin

Configuration

First you probably want to set up the sfNews.yml configuration file. The sfSimpleNewsPlugin comes with two helpers (latest_news() and news_archive()) that can just be used in your templates; but there must exist a page in your website which will be used to show the single news (and that must contain the show_news() helper). The plugin must know where this page is located, so you can specify this in the configuration file. The two most important settings are related to this topic:

  • the route_suffix parameter is actually the name of the module where the news will be displayed;
  • the news_page is the name of the action.

By default I use this plugin together with sfSimpleCMSPlugin, so the default configuration is "cms" for the route_suffix and "news" (a page to be created) for the news_page. The others parameters are quite self-explaining.

Usage

Before using sfSimpleNews helpers you need to load them with use_helper statement.

    <?php use_helper('sfSimpleNews'); ?>

Just put the latest_news() helper anywhere in your template, as well as the news_archive() helper; the title of each news should link to the page you configured into sfNews.yml. Create that page and put inside it the show_news() helper; if everything is fine here you should see the full news. You just need to customize the news.css file to suite your needs.

Changelog

2007-09-03: 0.1.0 alpha

  • Initial release

2007-09-03: 0.1.1 alpha

  • Added Italian translation for the admin generator
  • Extended the admin generator to have the "cancel" icon when a news is not published
  • Included sfYamlToSfConfigConfigHandler.php by Francois Zaninotto to manage configuration options

Todo

  • Add some nice css by default
  • Add rss support

Contacts

If you have any questions or feedback feel free to contact me at agiorg@gmail.com.

Please include sfSimpleNewsPlugin in the mail subject, this will help me tracking the conversation.

License

sfSimpleNewsPlugin is a symfony plugin created by Andrea Giorgini, strongly inspired by sfSimpleBlogPlugin created by Francois Zaninotto. The included library sfYamlToSfConfigConfigHandler.php is Copyright (c) 2004-2007 Francois Zaninotto For the full copyright and license information, please view the LICENSE file that was distributed with this source code.

Attachments