easy test for php function that take multiple objects as parameters - php

Hi Swagger/Restler friends,
How can I allow users to make easy test for php function and classes?
I have a class as follow:
class Author
{
/**
* #var string {#from body} {#min 3}{#max 100}
* name of the Author {#required true}
*/
public $name = 'Name';
/**
* #var string {#type email} {#from body}
* email id of the Author
*/
public $email = 'name#domain.com';
}
and I want to generate html documentation for a class that is as the follow:
class ComplexType {
/**
* post 2 Authors
*
* #param Author $author1
* #param Author $author2
*
* #return Author
*/
function post2Authors(Author $author1,Author $author2) {
return $author1;
}
}
It gives me when I run index.html the following to input:
{
"author1": "",
"author2": ""
}
But I need to view json input as follow:
{
"author1":
{
"name": "",
"email": ""
},
"author2": {
"name": "",
"email": ""
}
}
thank you in advance

Default value serves as an easy starter for trying the API with Restler API Explorer.
Currently it does not offer model parsing when more than one body parameter is found thus we are stuck with
{
"author1": "",
"author2": ""
}
We are working on support for Swagger 1.2 spec and along with that we will be releasing the full model parsing for default value along with that soon

Related

PHP Symfony NelmioApiDocBundle ignore methods in model class

I created the following class (simplified for the example) and using as #Model.
class Model
{
public string $name;
public function address(): string
{
return "$this->name#gmail.com";
}
public function isShort(): bool
{
return strlen($this->name) < 3;
}
}
The ApiDoc generator tries to interpret the functions as addSomething and isSomething so I obtain the model
{
"name": string,
"address": string,
"short": boolean
}
But I want only
{
"name": string
}
Is there a way to annotate the function to make them being ignored from the API doc renderer?
Use serialization groups for your entity for this purpose
1.In your controller, import
use OpenApi\Annotations as OA;
use Nelmio\ApiDocBundle\Annotation\Model;
2.Annotate your method with the desired model and serialization group. (In the example, this is the File:class entity and the file:read group)
/**
* #Route("/api/files", methods={"GET"})
* #OA\Response(
* response=200,
* description="Returns the Files",
* #OA\JsonContent(
* type="array",
* #OA\Items(ref=#Model(type=File::class, groups={"file:read"}))
* )
* )
* #OA\Tag(name="files")
*/
public function getFiles(){
//...
}
3.And finally specify in your serialization group entity to tell the api which properties to use.
class File
{
/**
* #Groups({"file:read"})
* #ORM\Column(name="filename", type="string")
*/
private string $filename;
/**
* #ORM\Column(name="extension", type="string")
*/
private string $extension;
}
4.Result. As we can see api doc ignores properties where the used serialization group is not set, in the example this property is extension.
{
"filename": string
}

Custom Symfony Action with API Platform bundle

I try to build an API with the Symfony bundle API-Platform.
Api resource offer automatic CRUD action with the HTTP verbs POST, GET, PUT, DELETE.
What I want is adding an endpoint to handle a custom POST action, with a custom payload/body, not depending on any resource.
Where I block it is to add this endpoint to the automatic API-Platform documentation.
When looking for this kind of issue on GitHub, I found that the API-Platform v2 should be able to do it.
See Issue #385 : Custom action + ApiDoc
It looks like some people find the way to use NelmioApiDoc #ApiDoc annotation.
See Issue #17 : Documentation for custom operation
Using the #ApiDoc annotation is a no go, support for NelmioApiDoc will be removed in API Platform 3 in favor of the builtin Swagger/Hydra support.
If you use a custom API Platform action, the action should automatically be documented in Swagger and Hydra docs.
Anyway, you can always customize the Swagger (and Hydra) docs to add custom endpoints or anything else: https://github.com/api-platform/docs/blob/master/core/swagger.md#override-swagger-documentation (this documentation will be available on the website soon).
You can document your own route with the #ApiResource() annotation:
/**
* #ORM\Entity
* #ApiResource(
* itemOperations={
* "get"={"method"="GET"},
* "put"={"method"="PUT"},
* "delete"={"method"="DELETE"},
* "send_reset_password_token"={
* "route_name"="user_send_reset_password_token",
* "swagger_context" = {
* "parameters" = {
* {
* "name" = "email",
* "in" = "path",
* "required" = "true",
* "type" = "string"
* }
* },
* "responses" = {
* "201" = {
* "description" = "email with reset token has been sent",
* "schema" = {
* "type" = "object",
* "required" = {
* "email"
* },
* "properties" = {
* "email" = {
* "type" = "string"
* },
* "fullname" = {
* "type" = "string"
* }
* }
* }
* },
* "400" = {
* "description" = "Invalid input"
* },
* "404" = {
* "description" = "resource not found"
* }
* },
* "summary" = "Send email with token to reset password",
* "consumes" = {
* "application/json",
* "text/html",
* },
* "produces" = {
* "application/json"
* }
* }
* }
* },
* attributes={
* "normalization_context"={"groups"={"user", "user-read"}},
* "denormalization_context"={"groups"={"user", "user-write"}}
* }
* )
*/
Source: https://github.com/api-platform/docs/issues/143#issuecomment-260221717
You can create custom post action like this.
Map resources configuration to yaml.
# config/packages/api_platform.yaml
api_platform:
enable_swagger_ui: false
mapping:
paths: ['%kernel.project_dir%/config/api_platform']
Create resources.yaml
# config/api_platform/resources.yaml
resources:
App\Entity\User:
itemOperations: []
collectionOperations:
post:
method: 'POST'
path: '/auth'
controller: App\Controller\AuthController
swagger_context:
summary: your desc
description: your desc
Then in App\Entity\User add public properties
class User {
public $login
public $password
}
It is all, now in swagger ui u will see method POST /api/auth with login and pass parameters.
In u controller override _invoke for execute your logic.
class AuthController {
public function __invoke()
{
return ['your custom answer'];
}
}
I ran into the same situation because I tried to put the POST method into itemOperations, although it can only reside in collectionOperations. In the latter in can successfully define my custom path.
/**
* #ApiResource(
* collectionOperations={
* "get"={
* "path"="/name_your_route",
* },
* "post"={
* "path"="/name_your_route",
* },
* },
* itemOperations={
* "get"={
* "path"="/name_your_route/group/{groupId}/user/{userId}",
* "requirements"={"groupId"="\d+", "userId"="\d+"},
* },
* "delete"={
* "path"="/name_your_route/group/{groupId}/user/{userId}",
* },
* "put"={
* "path"="/name_your_route/group/{groupId}/user/{userId}",
* }
* })
Hopefully helpful for others that stumble upon this question.
And here is the paragraph from the great documentation about it:
Collection operations act on a collection of resources. By default two
routes are implemented: POST and GET. Item operations act on an
individual resource. 3 default routes are defined GET, PUT and DELETE

Drupal 8.3 Custom Rest POST Error BadRequestHttpException: The type link relation must be specified

I have try to create a Custom REST POST plugin in my Drupal 8.3.2 for get an external JSON and then create an article from that.
I have follow that guide: How to create Custom Rest Resources for POST methods in Drupal 8
And this is my code:
<?php
namespace Drupal\import_json_test\Plugin\rest\resource;
use Drupal\Core\Session\AccountProxyInterface;
use Drupal\node\Entity\Node;
use Drupal\rest\Plugin\ResourceBase;
use Drupal\rest\ResourceResponse;
use Symfony\Component\DependencyInjection\ContainerInterface;
use Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException;
use Psr\Log\LoggerInterface;
/**
* Provides a resource to get view modes by entity and bundle.
*
* #RestResource(
* id = "tio_rest_json_source",
* label = #Translation("Tio rest json source"),
* serialization_class = "Drupal\node\Entity\Node",
* uri_paths = {
* "canonical" = "/api/custom/",
* "https://www.drupal.org/link-relations/create" = "/api/custom"
* }
* )
*/
class TioRestJsonSource extends ResourceBase {
/**
* A current user instance.
*
* #var \Drupal\Core\Session\AccountProxyInterface
*/
protected $currentUser;
/**
* Constructs a new TioRestJsonSource object.
*
* #param array $configuration
* A configuration array containing information about the plugin
instance.
* #param string $plugin_id
* The plugin_id for the plugin instance.
* #param mixed $plugin_definition
* The plugin implementation definition.
* #param array $serializer_formats
* The available serialization formats.
* #param \Psr\Log\LoggerInterface $logger
* A logger instance.
* #param \Drupal\Core\Session\AccountProxyInterface $current_user
* A current user instance.
*/
public function __construct(
array $configuration,
$plugin_id,
$plugin_definition,
array $serializer_formats,
LoggerInterface $logger,
AccountProxyInterface $current_user) {
parent::__construct($configuration, $plugin_id,
$plugin_definition, $serializer_formats, $logger);
$this->currentUser = $current_user;
}
/**
* {#inheritdoc}
*/
public static function create(ContainerInterface $container, array
$configuration, $plugin_id, $plugin_definition) {
return new static(
$configuration,
$plugin_id,
$plugin_definition,
$container->getParameter('serializer.formats'),
$container->get('logger.factory')->get('import_json_test'),
$container->get('current_user')
);
}
/**
* Responds to POST requests.
*
* Returns a list of bundles for specified entity.
*
* #param $data
*
* #param $node_type
*
* #return \Drupal\rest\ResourceResponse
*
* #throws \Symfony\Component\HttpKernel\Exception\HttpException
* Throws exception expected.
*/
public function post($node_type, $data) {
// You must to implement the logic of your REST Resource here.
// Use current user after pass authentication to validate access.
if (!$this->currentUser->hasPermission('access content')) {
throw new AccessDeniedHttpException();
}
$node = Node::create(
array(
'type' => $node_type,
'title' => $data->title->value,
'body' => [
'summary' => '',
'value' => $data->body->value,
'format' => 'full_html',
],
)
);
$node->save();
return new ResourceResponse($node);
}
}
Now if i try to test this without passing a payload and modifing the return value in this way:
return new ResourceResponse(array('test'=>'OK'));
It's working!
But if i send a custom payload like this using my custom code above:
{
"title": [{
"value": "Test Article custom rest"
}],
"type": [{
"target_id": "article"
}],
"body": [{"value": "article test custom"}]
}
I recieve a 400 Error with: Symfony\Component\HttpKernel\Exception\BadRequestHttpException: The type link relation must be specified. in Drupal\rest\RequestHandler->handle() (line 103 of core/modules/rest/src/RequestHandler.php).
What's going Wrong?
Thx.
I have find a solution:
I have removed the annotation:
* serialization_class = "Drupal\node\Entity\Node",
Then i take care just for data in my post function:
/**
* Responds to POST requests.
*
* Returns a list of bundles for specified entity.
*
* #param $data
*
*
* #return \Drupal\rest\ResourceResponse
*
* #throws \Symfony\Component\HttpKernel\Exception\HttpException
* Throws exception expected.
*/
public function post($data) {
// You must to implement the logic of your REST Resource here.
// Use current user after pass authentication to validate access.
if (!$this->currentUser->hasPermission('access content')) {
throw new AccessDeniedHttpException();
}
return new ResourceResponse(var_dump($data));
The important thing is, when you use postman for example, is to add an header with Content-Type -> application/json:
Instead of Content-Type -> application/hal+json
With this configuration i can post any type of JSON and then manage it as i prefer.
Bye!

processing inner object values that submitted from testing side to service side

Hi Restler/Swagger friends,
I have a problem when trying to submit values of object that have inner object values to service side..
what happened that object values submitted but inner object values didn't submitted to the service side or submitted but not processed at service side.....
How can i submit the inner object values or allow service side to take theses inner objects?
Do i need to update php at service side?
if yes where should i update?
please guide me
My test classes as follow:
/**
* POST
* post Author
*
* #param {#type Author} $a
*
* #return Author
*/
function postAuthor(Author $a) {
return $a->p->fname." ".$a->name;
}
//models
//inner object
class Person {
/**
* #var string {#from body}
* name of the Person {#required true}
*/
public $fname = 'First name';
/**
* #var string {#from body}
* last name of the Person {#required true}
*/
public $lname = 'Last name';
/**
* #var array $arr {#type array} array of IDs
* {#required true}
*/
public $arr = array();
}
//outer object
class Author {
/** define person as inner object
* #var Person $p {#type Person} {#from body} person of author
*
*/
public $p ;
/**
* #var string {#from body}
* name of the Author {#required true}
*/
public $name = 'Name';
/**
* #var string {#type email} {#from body}
* email id of the Author
*/
public $email = 'name#domain.com';
}
when i fill the values using json default value as follow:
{
"p":{
"fname": "aa",
"lname": "bb",
},
"name":"aa",
"email":"aa#hotmail.com"
}
then click Try it prints
{
"p": {
"fname": "First name",
"lname": "Last name",
"arr": []
},
"name": "aa",
"email": "aa#hotmail.com"
}
this means that json is submitted but inner object values not processed and not returned to test side.
We just released an update in V3 branch that fixes this. Check it out

RSS feed PHP/MySQL

Is there a good PHP Class to generate a RSS file from mysql tables?
There are ready to use classes for building rss feeds like this one found on phpclasses.org but it is just as easy to read up on the rss spec and generate the XML yourself with XMLWriter which is based on libxml and included in PHP5.
When you are actually generating the feeds yourself it never hurts to understand the spec.
I've wrote few hours ago small classes and tested it with feed validator and it work really fine.
Here source code
<?php
/**
* Top Level Element or RSS Feed 2.0.
*
* RSS Parent Element.
*
* #version 1.0
* #author makemoney2010
* #property array $Channels array of RSSChannell
*/
class RSS
{
public $Channels=array();
function __construct()
{
$this->Channels=array();
}
/**
* Add a new RSSChannell to the Channells
* #method void
* #param RSSChannell $RssChannell
*/
function addChannell($RssChannell)
{
$this->Channels[]=$RssChannell;
}
/**
* Clear all the item within the channells
* #method void
*/
function clearChannells()
{
$this->Channels=array();
}
/**
* Get full RSS xml
* #param boolean $forceCData Define is Cdata must be used or not this value will be propagated within all child RSSchannels and/or their itemChannell
* #return string Full RSS structure that should be used as response or even as string to put within a static file.
*/
function getOutputXML($forceCData)
{
$output='<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">';
foreach($this as $key=>$value)
{
if (is_array($value))
{
foreach($value as $key => $item)
{
/** #var RSSChannell $item */
$output.= $item->getOutputXML($forceCData);
}
}
//$output.=$value->getOutputXML($forceCData);
}
$output.='</rss>';
return $output;
}
}
/**
* Class Channell
* #property string $title Channell title REQUIRED NOT OPTIONAL IN RSS
* #property string $description Description of the channell REQUIRED NOT OPTIONAL IN RSS
* #property string $atomlink <atom:link href="http://dallas.example.com/rss.xml" rel="self" type="application/rss+xml" />
* #property string $copyright Copyright notice for content in the channel: Example {copyright 2002, Spartanburg Herald-Journal} OPTIONAL NOT REQUIRED IN RSS
* #property string $managingEditor Email address for person responsible for editorial content. Example {geo(et)herald.com (George Matesky)} OPTIONAL NOT REQUIRED IN RSS
* #property string $webMaster Email address for person responsible for technical issues relating to channel. Example {betty(et)herald.com (Betty Guernsey)} OPTIONAL NOT REQUIRED IN RSS
* #property string $language Language of the channell OPTIONAL NOT REQUIRED IN RSS
* #property string $pubDate The publication date for the content in the channel. For example, the New York Times publishes on a daily basis, the publication date flips once every 24 hours. That's when the pubDate of the channel changes. All date-times in RSS conform to the Date and Time Specification of RFC 822, with the exception that the year may be expressed with two characters or four characters (four preferred). Example {Sat, 07 Sep 2002 00:00:01 GMT} OPTIONAL NOT REQUIRED IN RSS
* #property string $lastBuildDate The last time the content of the channel changed. Example {Sat, 07 Sep 2002 09:42:31 GMT} OPTIONAL NOT REQUIRED IN RSS
* #property string $category Specify one or more categories that the channel belongs to. Follows the same rules as the <item>-level category element. OPTIONA NOT REQUIRED IN RSS
* #property string $generator A string indicating the program used to generate the channel. Example {MightyInHouse Content System v2.3}
* #property string $docs A URL that points to the documentation for the format used in the RSS file. It's probably a pointer to this page. It's for people who might stumble across an RSS file on a Web server 25 years from now and wonder what it is. More info at http://blogs.law.harvard.edu/tech/rss OPTIONAL NOT REQUIRED IN RSS
* #property string $cloud Allows processes to register with a cloud to be notified of updates to the channel, implementing a lightweight publish-subscribe protocol for RSS feeds. More info here. <cloud domain="rpc.sys.com" port="80" path="/RPC2" registerProcedure="pingMe" protocol="soap"/> OPTIONAL NOT REQUIRED IN RSS
* #property string $ttl ttl stands for time to live. It's a number of minutes that indicates how long a channel can be cached before refreshing from the source. OPTIONAL NOT REQUIRED IN RSS
* #property string $image Specifies a GIF, JPEG or PNG image that can be displayed with the channel OPTIONAL NOT REQUIRED IN RSS
* #property int $rating The PICS rating for the channel OPTIONAL NOT REQUIRED IN RSS
* #property int $skipHours A hint for aggregators telling them which hours they can skip OPTIONAL NOT REQUIRED IN RSS
* #property int $skipDays A hint for aggregators telling them which days they can skip OPTIONAL NOT REQUIRED IN RSS
* #method getCountItems() Get count of items inclued into array ChannellsItems
*/
class RSSChannell{
#region properties
public $language;
private $channellsItems=array();
public $atomlink;
public $title;
public $description;
public $pubDate;
public $copyright;
public $managingEditor;
public $webMaster;
public $lastBuildDate;
public $category;
public $generator;
public $docs;
public $cloud;
public $ttl;
public $image;
public $rating;
public $skipHours;
public $skipDays;
#endregion
#region void
/**
* Summary of __construct
* #param string $lang setup the channell language and the default array of ItemChannell
* #param array $channellsItems as collection of itemChannell
*/
function __construct($lang)
{
$this->language=$lang;
$this->channellsItems=array();
}
/**
* Clear all the items within the $channellsItems array
* #method void clearChannellItems()
*/
function clearChannellItems()
{
$this->channellsItems=array();
}
/**
* Add a new item to the channellsItems collection
* #method void addItemChannell(itemChannell $itemChannell)
* #param ItemChannell $itemChannell
*/
function addItemChannell($itemChannell)
{
$this->channellsItems[]=$itemChannell;
}
/**
* Set basic Email information within the feed about webmaster, copyright,managingEditor at once.If need it could be changed one by one setting its own right value.
* #param mixed $email
* #param mixed $name
*/
function setBasicEmail($email,$name)
{
$this->copyright=$email.' ('.$name.')';
$this->managingEditor=$email.' ('.$name.')';
$this->webMaster=$email.' ('.$name.')';
}
/**
* Set Email information about copyright.
* #param string $email
* #param string $name
* #method void
*/
function setCopyright($email,$name)
{
$this->copyright=$email.' ('.$name.')';
}
/**
* Set Email information about managingEditor
* #param string $email
* #param string $name
* #method void
*/
function setmanagingEditor($email,$name)
{
$this->managingEditor=$email.' ('.$name.')';
}
/**
* Set basic Email information about webmaster
* #param string $email
* #param string $name
* #method void
*/
function setwebMaster($email,$name)
{
$this->webMaster=$email.' ('.$name.')';
}
#endregion
#region functions
/**
* Return the count of all the items within channellsItems
* #return int
*/
function getCountItems()
{
return count($this->channellsItems);
}
/**
* #method function
* #param boolean $forceCData For default True indicate if use CDATA section within string field in order to prevent wrong markup in RSS feed too
*/
function getOutputXML($forceCData=true)
{
$output='<channel>';
$items='';
foreach($this as $key=>$value)
{
if(is_array($value))
{
$o=new ItemChannell();
foreach($value as $item)
{
/** #var ItemChannell $item */
$items.= $item->getOutputXML($forceCData);
}
}else
{
if(!empty($value) || $value !=null || $value!=0 || $value!='')
{
//cheking for atomlink element
if($key==='atomlink')
{
$output.='<atom:link href="'.$value.'" rel="self" type="application/rss+xml" />';
}
else{
if($forceCData)
{
$value=htmlspecialchars($value);
$output.=sprintf('<%1$s><![CDATA[%2$s]]></%1$s>',$key,$value);
}
else
{
$value=htmlspecialchars($value);
$output.=sprintf('<%1$s>%2$s</%1$s>',$key,$value);
}
}
}
}
}
$output.=$items;
$output.='</channel>';
return $output;
}
#endregion
}
/**
* Class ItemChannel exposes all the properties within a fully compliant RSS item element
* #property string $title The title of the item. Example: Venice Film Festival Tries to Quit Sinking
* #property string $link The URL of the item. Example: http://nytimes.com/2004/12/07FEST.html
* #property string $description Example: The item synopsis.Some of the most heated chatter at the Venice Film Festival this week was about the way that the arrival of the stars at the Palazzo del Cinema was being staged.
* #property string $author Email address of the author of the item.
* #property string $category Includes the item in one or more categories.
* #property string $comments URL of a page for comments relating to the item. Example: http://www.myblog.org/cgi-local/mt/mt-comments.cgi?entry_id=290
* #property string $enclosure Describes a media object that is attached to the item.
* #property string $guid A string that uniquely identifies the item.
* #property datetime $pubDate Indicates when the item was published. Example: Sun, 19 May 2002 15:21:36 GMT
* #property string $source The RSS channel that the item came from.
*/
class ItemChannell{
#region properties
public $title;
public $link;
public $description;
public $author;
public $category;
public $comments;
public $enclosure;
public $guid;
public $pubDate;
public $source;
#endregion
#region void
/**
* Constructor of the Items
*/
function __construct()
{
//Nothing required
}
/**
* Set the title of the item
* #method void
* #param string $title
*/
function setTitle($title)
{
$this->title=$title;
}
/**
* Set the link of the item
* #method void
* #param string $link
*/
function setLink($link)
{
$this->link=$link;
}
/**
* Set the description of the item
* #method void
* #param string $description
*/
function setDescription($description)
{
$this->description=$description;
}
/**
* Set the author of the item
* #method void
* #param string $author
*/
function setAuthor($author)
{
$this->author=$author;
}
/**
* Set the category of the item
* #method void
* #param string $category
*/
function setCategory($category)
{
$this->category=$category;
}
/**
* Set comments url of the item
* #method void
* #param mixed $comments
*/
function setCommentsUrl($comments)
{
$this->comments=$comments;
}
/**
* Set enclosure of item
* #method void
* #param string $enclosure
*/
function setEnclosure($enclosure)
{
$this->enclosure=$enclosure;
}
/**
* Set guid of the item
* #method void
* #param string $guid
*/
function setGuidItem($guid)
{
$this->guid=$guid;
}
/**
* Set pubdate of the item
* #method void
* #param datetime $pubDate
*/
function setPubDate($pubDate)
{
$this->pubDate=$pubDate;
}
/**
* Set source of item
* #method void
* #param string $source
*/
function setSource($source)
{
$this->source=$source;
}
#endregion
#region function
/**
* Get the output in xml format for the rss item
* #method function
* #param boolean $forceCDATA Include all the item of type string within a CDATA section in order to prevent issues.Default use it.
* #return string Xml well formatted as requires
*/
function getOutputXML($forceCDATA=true)
{
$output='<item>';
foreach($this as $key=> $value)
{
if(!empty($value) || $value !=null || $value!=0 || $value!='')
{
if($forceCDATA)
{
$value=htmlspecialchars($value);
$output.=sprintf('<%1$s><![CDATA[%2$s]]></%1$s>',$key,$value);
}
else
{
$output.=sprintf('<%1$s>%2$s</%1$s>',$key,$value);
}
}
}
$output.='</item>';
return $output;
}
#endregion
}
With that file you have complete access to all the classes that you could need to create a complete RSS.
Here below a simple example of the use of those classes
function test()
{
//Define a basic RSS object which represent the root ot the RSS Feed too
$rss= new RSS();
//Declare a RSS Channell object and fill the property that you need here below a simple example
$rssChan= new RSSChannell('en');
$rssChan->title='This is my first Channell RSS';
$rssChan->description='this channell is very cool and is built in a simple manner with a specialized class';
$rssChan->category='Category';
$rssChan->setBasicEmail('domain#domain.com','Jhon Doe');
$rssChan->atomlink='http://domain.com/';
$rssChan->link='http://domain.com/';
//Add the channell to the rss root to
$rss->addChannell($rssChan);
//create a simple iteration in order to create specialized list of ItemChannel whith will be used as item in the RSSChannell above
for ($i = 0; $i < 10; $i++)
{
$rssItem= new ItemChannell();
$rssItem->guid='http://domain.com/'.$i;
$rssItem->setCategory('Category names in this fields '.$i);
$rssItem->setAuthor('jhondoe#domain.com (Jhon Doe)');
$rssItem->setDescription('this is a description item within rss');
//Add each item to the RSSChannell collection
$rssChan->addItemChannell($rssItem);
}
//print output into your page don\'t forget that this is an xml output and so you have to set your header as application/xml.
header('Content-Type: application/xml');
//call RSS root Method getOutputXML($bool) (Take a look into description of all methods properties of the class),
echo $rss->getOutputXML(false);
}
That's all you will have a full RSS feed done.
There are more available stuff that could be implemented into the classes but as i need just this have no extened to much this one however you can extend with method to save into a file, append to a file a more other stuff.
I hope this could be a good point to start in order to have a simple way to achieve your goal and make it very easier.
Regards
Makemoney2010
You can use XMLDOM. RSS is just XML.

Categories