NAME
Mojolicious::Plugin::ContentManagement::Source::DBI - content from database
SYNOPSIS
my $dbh = DBI->connect(...);
# Mojolicious
$self->plugin( content_management => {
source => 'dbi',
source_conf => { dbh => $dbh, prefix => 'foo' },
...
});
# Mojolicious::Lite
plugin content_management => {
source => 'dbi',
source_conf => { dbh => $dbh, prefix => 'foo' },
...
};
DESCRIPTION
This is the database source, using DBI. You just need a table like this:
CREATE TABLE foo_pages (
path VARCHAR(100),
parent VARCHAR(100),
sort VARCHAR(10),
title VARCHAR(100),
raw VARCHAR(10000),
PRIMARY KEY (path)
);
Create a few rows and the pages are available in your webapp immediately. Two example pages:
INSERT INTO foo_pages (path, parent, sort, title, raw)
VALUES ('/foo.html', NULL, '03', 'This is /foo.html', 'Yay');
INSERT INTO foo_pages (path, parent, sort, title, raw)
VALUES ('/foo/bar.html', '/foo.html', '02', 'This is /foo/bar.html', 'Yay');
As you can see, the parent field is used to reference the parent of a page, the sort field is used to defined the order of all pages on the same level.
CONFIGURATION
With the source_conf
hash ref you can pass the dbh
, which must be a DBI database handle. Also you can pass a prefix
for the pages table. Without the prefix, the table pages
is used, if you pass foo
as a prefix
, the table foo_pages
is used.
METHODS
This class implements all abstract methods of its base class Mojolicious::Plugin::ContentManagement::Source
SEE ALSO
Mojolicious::Plugin::ContentManagement, Mojolicious::Plugin::ContentManagement::Source