Catalyst-Manual

 view release on metacpan or  search on metacpan

lib/Catalyst/Manual/Tutorial/03_MoreCatalystBasics.pod  view on Meta::CPAN

    </body>
    </html>

Notice the status and error message sections in the code above:

    <span class="status">[% status_msg %]</span>
    <span class="error">[% error_msg %]</span>

If we set either message in the Catalyst stash (e.g.,
C<< $c->stash->{status_msg} = 'Request was successful!' >>) it will
be displayed whenever any view used by that request is rendered.  The
C<message> and C<error> CSS styles can be customized to suit your needs
in the F<root/static/css/main.css> file we create below.

B<Notes:>

=over 4

=item *

The Catalyst stash only lasts for a single HTTP request.  If you need to
retain information across requests you can use
L<Catalyst::Plugin::Session> (we will use Catalyst sessions in the
Authentication chapter of the tutorial).

=item *

Although it is beyond the scope of this tutorial, you may wish to use a
JavaScript or AJAX tool such as jQuery (L<https://www.jquery.com>) or
Dojo (L<https://dojotoolkit.org/>).

=back


=head3 Create A Basic Stylesheet

First create a central location for stylesheets under the static
directory:

    $ mkdir root/static/css

Then open the file F<root/static/css/main.css> (the file referenced in
the stylesheet href link of our wrapper above) and add the following
content:

    #header {
        text-align: center;
    }
    #header h1 {
        margin: 0;
    }
    #header img {
        float: right;
    }
    #footer {
        text-align: center;
        font-style: italic;
        padding-top: 20px;
    }
    #menu {
        font-weight: bold;
        background-color: #ddd;
    }
    #menu ul {
        list-style: none;
        float: left;
        margin: 0;
        padding: 0 0 50% 5px;
        font-weight: normal;
        background-color: #ddd;
        width: 100px;
    }
    #content {
        margin-left: 120px;
    }
    .message {
        color: #390;
    }
    .error {
        color: #f00;
    }

You may wish to check out a "CSS Framework" like Emastic
(L<http://code.google.com/p/emastic/>) as a way to quickly provide lots
of high-quality CSS functionality.


=head2 Test Run The Application

Hit "Reload" in your web browser and you should now see a formatted
version of our basic book list. (Again, the development server should
have automatically restarted when you made changes to
F<lib/MyApp/View/HTML.pm>. If you are not using the "-r" option, you
will need to hit C<Ctrl-C> and manually restart it. Also note that the
development server does I<NOT> need to restart for changes to the TT and
static files we created and edited in the C<root> directory -- those
updates are handled on a per-request basis.)

Although our wrapper and stylesheet are obviously very simple, you
should see how it allows us to control the overall look of an entire
website from two central files. To add new pages to the site, just
provide a template that fills in the C<content> section of our wrapper
template -- the wrapper will provide the overall feel of the page.


=head2 Updating the Generated DBIx::Class Result Class Files

If you take a look at the Schema files automatically generated by
L<DBIx::Class::Schema::Loader>, you will see that it has already defined
C<has_many> and C<belongs_to> relationships on each side of our foreign
keys. For example, take a look at F<lib/MyApp/Schema/Result/Book.pm> and
notice the following code:

    =head1 RELATIONS

    =head2 book_authors

    Type: has_many

    Related object: L<MyApp::Schema::Result::BookAuthor>



( run in 0.581 second using v1.01-cache-2.11-cpan-f56aa216473 )