CatalystX::ExtJS::Tutorial - Introduction to CatalystX::ExtJS


version 2.1.3





These tasks are referenced from the tutorials above.

Step 1: Bootstrap Catalyst

In order to run the examples we need to bootstrap a Catalyst application.

First go to your working directory and run:

 # MyApp

This will create a basic Catalyst application. Open up lib/ and add Unicode to the list of plugins (after Static::Simple).

Step 2: Add the Template View

Next we need a view. We will go with a Template::Alloy view which will take care of rendering the HTML and JavaScript sources. Create lib/MyApp/View/ with:

 package MyApp::View::TT;
 use Moose;
 extends 'Catalyst::View::TT::Alloy';

 __PACKAGE__->config( {
         CATALYST_VAR => 'c',
         INCLUDE_PATH => [ MyApp->path_to( 'root', 'src' ) ]
     } );

Step 3: Adjust the Root Controller

The JavaScript sources should be generated through the view we just created. For this to work, we need a controller, which handles that. We can use the Root controller which was created when we created MyApp. Open up lib/MyApp/Controller/ and change the index subroutine to:

 sub index :Path :Args(0) { }

This removes the Catalyst welcome message and a request to / will run the index template (which we will create later) via the TT view.

Step 4: Add the index Template

Now it's time to build some HTML and JavaScript. Add this to root/src/index:

 <title>Ext.Direct and Catalyst</title>
 <link rel="stylesheet" type="text/css" href="" />
 <script type="text/javascript" src=""></script>
 <script type="text/javascript" src=""></script>
 <script type="text/javascript" src="/api/src"></script>
 <body>Hello World!</body>

Step 5: Add the Direct API Controller

To have access to the API we need to add a new controller. Create lib/MyApp/Controller/ and paste:

 package MyApp::Controller::API;
 use Moose;
 extends q(CatalystX::Controller::ExtJS::Direct::API);

Now we create an action which will route any request to /js/* to the according template in root/src/js.

 sub js : Path : Args {
    my ($self, $c, $template) = @_;
    $c->stash->{template} = $template;

Step 6: Add a DBIC Model

To play around with actual data, we need to set up a model. We will be using DBIx::Class as ORM which means we have to set up a DBIC schema first.

Create the file lib/MyApp/ and paste the following:

 package MyApp::Schema;
 use Moose;
 extends 'DBIx::Class::Schema';

Now we need a result class which describes the user object. Create lib/MyApp/Schema/Result/

 package MyApp::Schema::Result::User;
 use Moose;
 extends 'DBIx::Class::Core';
    id => { is_auto_increment => 1, data_type => 'integer' },
    qw(email first last)

To glue the DBIC schema and Catalyst together we create a model called MyApp::Model::DBIC. Paste the following in lib/MyApp/Model/

 package MyApp::Model::DBIC;
 use Moose;
 extends 'Catalyst::Model::DBIC::Schema';
 # we connect to an in-memory database
 # which means that the database is reset
 # with every start of the application
    schema_class => 'MyApp::Schema',
    connect_info => ['dbi:SQLite:dbname=:memory:']
 # this initializes the empty sqlite database 
 # and inserts one record
 after BUILD => sub {
    my $self = shift;
    my $schema = $self->schema;
        email => '', 
        first => 'Moritz', 
        last => 'Onken'


Moritz Onken <>


This software is Copyright (c) 2011 by Moritz Onken.

This is free software, licensed under:

  The (three-clause) BSD License