[jifty-devel] Reusing Jifty models outside Jifty apps
Jesse Vincent
jesse at bestpractical.com
Sat Dec 9 16:50:14 EST 2006
What I do looks like this:
#!/usr/bin/env perl
use lib '../Jifty/lib';
use lib 'lib';
use Jifty::Everything;
use BTDT::CurrentUser;
use BTDT::Model::User;
use Getopt::Long;
Jifty->new();
my $email;
my $type = 'guest';
GetOptions('email=s' => \$email, 'type=s' => \$type);
my $u = BTDT::Model::User->new(current_user => BTDT::CurrentUser-
>superuser);
my ($id,$msg) = $u->create(name => 'admin', email => $email, password
=> 'password', email_confirmed => 1, access_level => $type);
print $msg unless ($id);
1;
On Dec 9, 2006, at 6:28 AM, Agent Zhang wrote:
> Hello,
>
> I've found that It's often desired to reuse Jifty Models in off-
> line database importing/exporting scripts. Currently I'm using the
> following piece of code in my Qooqle project's off-line scripts:
>
> use UNIVERSAL::require;
> use Jifty::Config;
> use Jifty::ClassLoader;
>
> BEGIN {
> Jifty::ClassLoader->new(base => 'Qooqle')->require;
> }
>
> my $config = Jifty::Config->new;
> $config->load;
> my $db_config = $config->framework('Database');
> use Jifty::DBI::Handle;
> my $handle = Jifty::DBI::Handle->new();
> $handle->connect(
> driver => $db_config->{Driver},
> database => $db_config->{Database},
> user => $db_config->{User},
> password => $db_config->{Password},
> );
> Jifty->new( handle => $handle );
>
> Yes, it's ugly, but I can't make it shorter. What's the best
> practice for doing this in the Jifty world?
>
> Thanks!
> Agent
> _______________________________________________
> jifty-devel mailing list
> jifty-devel at lists.jifty.org
> http://lists.jifty.org/cgi-bin/mailman/listinfo/jifty-devel
More information about the jifty-devel
mailing list