Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Sample Gbook

  • Loading branch information...
commit bd893d063fc500ae3f2f95b9500fc91f8879f317 1 parent 8c2f790
@yuqkevin authored
View
6 sample/main.inc.phps
@@ -0,0 +1,6 @@
+<?php
+/*** default component
+ * @description Listing latest guest messages
+***/
+$limit = 20;
+$this->stream['data']['lines'] = $this->post_search(null, "order by post_id desc limit $limit");
View
42 sample/main.tpl.phps
@@ -0,0 +1,42 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<title>Sample: Guest Book</title>
+<meta http-equiv="content-type" content="text/html;charset=utf-8" />
+<meta name="keywords" content="" />
+<meta name="description" content="" />
+<style style="text/css">
+li:nth-child(odd) {background:#eee;}
+li span.action {visibility:hidden;float:right;}
+li:hover span.action {visibility:visible;}
+li:hover {background:#ddd;}
+</style>
+</head>
+<body>
+<h1 id="page-header">Sample: Guest Book <a href="/SampleGbook/writer" style="font-weight:normal;font-size:13px;">New Message</a></h1>
+<hr />
+<div id="page-body">
+<?php if ($lines):?>
+<form method="post" action="/SampleGbook/maintainer">
+<ul>
+ <?php foreach ($lines as $line):?>
+ <li><?php if ($line['ip']==$_SERVER['REMOTE_ADDR']):?>
+ <span class="action">
+ <button type="submit" name="edit" value="<?php print $line['id'];?>">Edit</button>
+ <button type="submit" name="del" value="<?php print $line['id'];?>">Delete</button>
+ </span>
+ <?php endif;?>
+ <strong><?php print htmlspecialchars($line['guest']);?></strong>@<em><?php print $line['timestamp'];?></em>
+ <div><?php print htmlspecialchars($line['content']);?></div>
+ </li>
+ <?php endforeach;?>
+</ul>
+</form>
+<?php else:?>
+No message found
+<?php endif;?>
+</div>
+<hr />
+<div id="page-footer">Sample for SimplyPHP</div>
+</body>
+</html>
View
24 sample/maintainer.inc.phps
@@ -0,0 +1,24 @@
+<?php
+$target = array('url'=>'/SampleGbook/');
+$this->stream['data']['message'] = null;
+if ($id=$this->request('del','post')) {
+ if ($this->post('delete', $id)) {
+ $target['message'] = "OK, the message has been deleted.";
+ } else {
+ $this->stream['data']['message'] = "Sorry, failed to delete the message.";
+ $this->stream['data']['post'] = $this->post('read', $id);
+ return;
+ }
+} elseif ($id=$this->request('edit','post')) {
+ $this->stream['data']['post'] = $this->post('read', $id);
+ return;
+} elseif ($id=$this->request('update','post')) {
+ if ($this->post('update', $id, array('content'=>$this->request('content','post')))) {
+ $target['message'] = "OK, the message has been updated.";
+ } else {
+ $this->stream['data']['message'] = "Sorry, failed to update message.";
+ $this->stream['data']['post'] = $this->post('read', $id);
+ return;
+ }
+}
+$this->redirect($target);
View
26 sample/maintainer.tpl.phps
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<title>Sample: Guest Book</title>
+<meta http-equiv="content-type" content="text/html;charset=utf-8" />
+<meta name="keywords" content="" />
+<meta name="description" content="" />
+</head>
+<body>
+<h1 id="page-header">Sample: Guest Book <span style="font-weight:normal;font-size:13px;">Edit Posted Message</span></h1>
+<hr />
+<div id="page-body" style="width:800px;">
+ <div style="color:red;"><?php print $message;?></div>
+ <form method="post">
+ <div><strong><?php print htmlspecialchars($post['guest']);?></strong> posted at <em><?php print $post['timestamp'];?></em>
+ <label>Message</label><br /><textarea name="content" style="width:100%; height:5em;"><?php print htmlspecialchars($post['content']);?></textarea><br />
+ <div style="text-align:right;padding-right:1em;">
+ <button type="button" onClick="window.location.href='/SampleGbook/'">Cancel</button>
+ <button type="submit" name="update" value="<?php print $post['id'];?>">Submit</button>
+ </div>
+ </form>
+</div>
+<hr />
+<div id="page-footer">Sample for SimplyPHP</div>
+</body>
+</html>
View
22 sample/writer.inc.phps
@@ -0,0 +1,22 @@
+<?php
+$this->stream['data']['message'] = "Hi, please leave your message here.";
+if (isset($_POST['new'])) {
+ $param = array(
+ 'guest'=>$this->request('guest','post')?$this->request('guest'):'Anonymous',
+ 'content'=>$this->request('content','post')
+ );
+ if (!$param['content']) {
+ $this->stream['data']['message'] = "Sorry, what message do you want to leave here?";
+ return;
+ }
+ if ($this->post('create', 0, $param)) {
+ $target = array(
+ 'url'=>'/SampleGbook/', // redirect to listing page
+ 'delay'=>2, // delay in seconds
+ 'message'=>'Thank you! your message has been submitted, and it will be redirected to listing page shortly.'
+ );
+ $this->redirect($target);
+ } else {
+ $this->stream['data']['message'] = "Sorry, failed to sumit your message.";
+ }
+}
View
26 sample/writer.tpl.phps
@@ -0,0 +1,26 @@
+<!DOCTYPE html>
+<html lang="en-us">
+<head>
+<title>Sample: Guest Book</title>
+<meta http-equiv="content-type" content="text/html;charset=utf-8" />
+<meta name="keywords" content="" />
+<meta name="description" content="" />
+</head>
+<body>
+<h1 id="page-header">Sample: Guest Book <span style="font-weight:normal;font-size:13px;">New Message</span></h1>
+<hr />
+<div id="page-body" style="width:800px;">
+ <div style="color:red;"><?php print $message;?></div>
+ <form method="post">
+ <label>Guest Name</label><br /><input type="text" name="guest" placeholder="Guest Name" style="width:100%;"/><br />
+ <label>Message</label><br /><textarea name="content" style="width:100%; height:5em;"></textarea><br />
+ <div style="text-align:right;padding-right:1em;">
+ <button type="button" onClick="window.location.href='/SampleGbook/'">Cancel</button>
+ <button type="submit" name="new">Submit</button>
+ </div>
+ </form>
+</div>
+<hr />
+<div id="page-footer">Sample for SimplyPHP</div>
+</body>
+</html>
View
4 sample_gbook.html
@@ -145,9 +145,9 @@ <h2 id="project_tagline">Learn by example II: First Database-Driven Application
<pre class="full black">
beans/sample/gbook/ --+-- lib.class.php, model.class.php
|
- +-- handler -- <a href="sample/main.inc.html">main.inc.php</a>,<a href="sample/maintainer.inc.html">maintainer.inc.php</a>,<a href="sample/writer.inc.html">writer.inc.php</a>
+ +-- handler -- <a href="sample/main.inc.phps">main.inc.php</a>,<a href="sample/maintainer.inc.phps">maintainer.inc.php</a>,<a href="sample/writer.inc.phps">writer.inc.php</a>
|
- +-- view -- <a href="sample/main.tpl.html">main.tpl.php</a>,<a href="sample/maintainer.tpl.html">maintainer.tpl.php</a>,<a href="sample/writer.tpl.html">writer.tpl.php</a>
+ +-- view -- <a href="sample/main.tpl.phps">main.tpl.php</a>,<a href="sample/maintainer.tpl.phps">maintainer.tpl.php</a>,<a href="sample/writer.tpl.phps">writer.tpl.php</a>
|
+-- database -- db.sql, db.tbl.ini
</pre>
Please sign in to comment.
Something went wrong with that request. Please try again.