Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Can't call method "find" on an undefined value

by CountZero (Bishop)
on Jan 12, 2012 at 19:56 UTC ( [id://947620]=note: print w/replies, xml ) Need Help??


in reply to Can't call method "find" on an undefined value

You will have to show the script that gives you this error.

CountZero

A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

Replies are listed 'Best First'.
Re^2: Can't call method "find" on an undefined value
by Anonymous Monk on Jan 12, 2012 at 20:06 UTC
    here is the code
    package AddressBook::Controller::Address; use strict; use warnings; use base qw(Catalyst::Controller::FormBuilder Catalyst::Controller::Bi +ndLex); use Data::Dumper; sub edit : Local Form { my ($self, $c, $address_id, $person_id) = @_; my $address : Stashed; print $c->request->arguments->[0]; print "\n"; print Dumper(" address_id is: ".Dumper($address_id)); print Dumper("person_id is: ".Dumper($person_id)); my $persid = $c->model('AddressDB::Addresses')->find({person => $id}); my $person = $c->model('AddressDB::People')->find({id => $persid}); if ($self->formbuilder->submitted && $self->formbuilder->validate){ # transfer data from form to database $address->location($self->formbuilder->field('location')); $address->postal ($self->formbuilder->field('postal' )); $address->phone ($self->formbuilder->field('phone')); $address->email ($self->formbuilder->field('email')); $address->insert_or_update; $c->stash->{message} = ($address_id > 0 ? 'Updated ' : 'Added new ').'address for '. $ +address->person->name; $c->detach('list'); } else { # transfer data from database to form if(!$address_id){ $c->stash->{message} = 'Adding a new address '; } else { $c->stash->{message} = 'Updating an address '; } $c->stash->{message} .= ' for '. $address->person->name; $self->formbuilder->field(name => 'location', value => $address +->location); $self->formbuilder->field(name => 'postal', value => $address-> +postal); $self->formbuilder->field(name => 'phone', value => $address->p +hone); $self->formbuilder->field(name => 'email', value => $address->e +mail); } }
    thanks
      the problem is in this line  my $persid = $c->model('AddressDB::Addresses')->find({person => $id});

        That line, or perhaps the next one. They both call a find method.

        Whichever line it is though, the problem is that the call to $c->model is returning undef.

        i've tried to see what's in  c->model and came up with this error Use of uninitialized value $_[0] in join or string at /usr/local/share/perl/5.10.1/Catalyst/Log.pm line 88. and this is the line 88  my $message = join( "\n", @_ ); from fct
        sub _log { my $self = shift; my $level = shift; my $message = join( "\n", @_ ); $message .= "\n" unless $message =~ /\n$/; my $body = $self->_body; $body .= sprintf( "[%s] %s", $level, $message ); $self->_body($body); }
        any idea?

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://947620]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-03-19 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found