Commits

kenjis committed 44073d7

blog sample code

  • Participants
  • Parent commits 6622876

Comments (0)

Files changed (5)

+CREATE TABLE IF NOT EXISTS `posts` (
+  `id` int(11) NOT NULL AUTO_INCREMENT,
+  `name` varchar(255) NOT NULL,
+  `text` text,
+  `created` datetime DEFAULT NULL,
+  `modified` datetime DEFAULT NULL,
+  PRIMARY KEY (`id`)
+) ENGINE=InnoDB  DEFAULT CHARSET=utf8;
+

fuel/app/classes/controller/blog.php

+<?php
+
+/**
+ * The Blog Controller.
+ * 
+ * @package  app
+ * @extends  Controller
+ */
+class Controller_Blog extends Controller
+{
+
+	/**
+	 * Hello World!
+	 * 
+	 * @access  public
+	 * @return  Response
+	 */
+	public function action_index()
+	{
+		echo 'Hello World!';
+	}
+
+	/**
+	 * Show one article.
+	 * 
+	 * @access  public
+	 * @return  Response
+	 */
+	public function action_view($id = 0)
+	{
+		$data = array();
+		$data['query'] = Model_Blog::read_data($id);
+		
+		if (empty($data['query']))
+		{
+			echo 'blog not found';
+		}
+		else
+		{
+			return View::forge('blog/view', $data);
+		}
+	}
+}

fuel/app/classes/model/blog.php

+<?php
+
+class Model_Blog extends Model {
+	
+	public static function read_data($id)
+	{
+		$result = DB::query('SELECT * FROM `posts` WHERE `id` = ' . intval($id) . ' LIMIT 1')->execute();
+		return $result->as_array();
+	}
+}

fuel/app/config/development/db.php

 
 return array(
 	'default' => array(
-		'connection'  => array(
-			'dsn'        => 'mysql:host=localhost;dbname=fuel_dev',
-			'username'   => 'root',
-			'password'   => 'root',
+		'type'			=> 'mysql',
+		'connection'	=> array(
+			'hostname'		=> 'localhost',
+			'port'			=> '3306',
+			'database'		=> 'blog',
+			'username'		=> 'root',
+			'password'		=> '',
+			'persistent'	=> false,
 		),
+		'table_prefix'	=> '',
+		'charset'		=> 'utf8',
+		'caching'		=> false,
+		'profiling'		=> false,
 	),
 );

fuel/app/views/blog/view.php

+<html>
+<head>
+<title>My Blog</title>
+</head>
+<body>
+
+  <h1><?php echo $query[0]['name']; ?></h1>
+  <p><small>Created: <?php echo $query[0]['created']; ?></small></p>
+  <p><small>Updated: <?php echo $query[0]['modified']; ?></small></p>
+  <p><?php echo nl2br($query[0]['text']); ?></p>
+
+</body>
+</html>