Meadows of wild horses

Blog...

Catalyst

| Comments

/list/write.tt 페이지

write.tt

form action

<form action="[% c.uri_for('/list/write') %]" method="POST">

direction setting

<td colspan=10 align=center>
  <input type=submit class="btn btn-primary" value="글 저장하기">
  &nbsp;&nbsp;
  <input type=reset class="btn btn-primary" value="다시 쓰기">
  &nbsp;&nbsp;
  <a href="[% c.uri_for('/list') %]" class="btn btn-primary">되돌아가기</a>
</td>

list -> write

$ lib/Silex/Web/Donnenwa/Controller/List.pm

sub write :Local :Args(0) {
my ( $self, $c ) = @_;

if ($c->req->method eq 'POST') {
    my %row = (
    name    => $c->req->params->{name},
    title   => $c->req->params->{title},
    content => $c->req->params->{content},
    );
    $c->model('DonDB')->resultset('List')->update_or_create(\%row);
    $c->res->redirect($c->uri_for('/list'));
}
}

/list/view.tt 페이지

view.tt

인자 출력

// 제목
<tr>
  <td height=20 colspan=4 align=center bgcolor=#999999>
<font color=white><b>[% users.title %]</b></font>
  </td>
</tr>

// 이름
<tr>
  <td width=50 height=20 align=center bgcolor=#EEEEEE>글쓴이</td>
  <td width=240 bgcolor=white>[% users.name %]</td>
</tr>

// 내용
<tr>
  <td bgcolor=white colspan=4 style="table-layout:fixed;">
<font color=black>
  [% users.content %]
</font>
  </td>
</tr>

list page redirect

<a href="[% c.uri_for('/list') %]" class="btn btn-primary">되돌아가기</a>

list -> view

$ lib/Silex/Web/Donnenwa/Controller/List.pm

sub view :Local :CaptureArgs(1) {
my ( $self, $c, $user_id) = @_;

my $rs = $c->model('DonDB')->resultset('List')->find($user_id);
$c->stash->{users} = $rs;
}

Comments