Skip to content

Commit

Permalink
add edit method
Browse files Browse the repository at this point in the history
  • Loading branch information
freefcw committed Mar 22, 2012
1 parent e561dfd commit e8a9d7c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 4 deletions.
51 changes: 47 additions & 4 deletions approot/application/classes/controller/client.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,51 @@ public function action_list()
$client_list = $m->get_page($page);

$body = View::factory('client/list');

$body->set_global('title', "Client Page {$page}");
$body->bind('client_list', $client_list);

$this->body = $body;
}

public function action_edit()
{
$client_id = $this->request->param('cid', null);
if ($this->request->method() == 'POST')
{
$post = $this->request->post();
var_dump($post);
exit();

if ($client_id === null) $this->request->redirect('/login');
// logo will save by another way
$data = array(
'client_name' => $post['client_name'],
'client_log' => $post['client_logo'],
'content' => $post['content'],
);

$m = new Model_Client();

$client_id = Arr::get($post, 'client_id');

if ($client_id === null)
{
list($client_id, $row) = $m->new_client($data);
} else {
$m->update_client($data);
}
} else {
$client_id = $this->request->param('cid', null);
if ($client_id === null) $this->request->redirect('/login');

$m = new Model_Client();
}

$m = new Model_Client();
$client = $m->get_client($client_id);

$body = View::factory('client/edit');

$body->set_global('title', "Edit Client {$client['name']}");

$this->body = $body;
}

Expand All @@ -41,6 +70,20 @@ public function action_del()
}

public function action_new()
{}
{
$client = array(
// 'client_id' => '',
'client_name' => '',
'client_log' => '',
'content' =>''
);

$body = View::factory('client/edit');

$body->set_global('title', 'Add new Client');
$body->bind('client', $client);

$this->body = $body;
}

} // End Welcome
38 changes: 38 additions & 0 deletions approot/application/views/client/edit.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<form class="form-horizontal" action="/client/edit" method="POST">
<?php if (array_key_exists('client_id', $client)):?>
<input type="hidden" name="client_id" id="client_id" value="<?php echo $client['client_id'];?>" />
<legend>Edit Client</legend>
<?php else: ?>
<legend>Add Client</legend>
<?php endif;?>
<fieldset>
<div class="control-group">
<label class="control-label" for="client_name">Name</label>
<div class="controls">
<input type="text" class="input-xlarge" id="client_name" name="client_name" value="<?php echo $client['client_name'];?>" />
<p class="help-block">Client Name</p>
</div>
</div>
<div class="control-group">
<?php if (array_key_exists('client_id', $client)):?>
<img class="client_log" src="<?php echo $client['client_log'];?>"/>
<input type="hidden" name="client_log" value="<?php echo $client['client_log'];?>" />
<?php endif;?>
<label class="control-label" for="fileInput">Client Logo</label>
<div class="controls">
<input class="input-file" id="fileInput" type="file">
<p class="help-block">If not modify then left blank.</p>
</div>
</div>
<div class="control-group">
<label class="control-label" for="content">Content</label>
<div class="controls">
<textarea rows="10" cols="50" class="input-xxlarge" name="content" id="content"><?php echo $client['content'];?></textarea>
</div>
</div>
<div class="form-actions">
<button type="submit" class="btn btn-primary">Save changes</button>
<button class="btn">Cancel</button>
</div>
</fieldset>
</form>

0 comments on commit e8a9d7c

Please sign in to comment.