Commits

Yasushi Ichikawa committed 316c117

blog sample code

  • Participants
  • Parent commits 7f2a005

Comments (0)

Files changed (4)

File application/config/database.php

 $active_record = TRUE;
 
 $db['default']['hostname'] = 'localhost';
-$db['default']['username'] = '';
-$db['default']['password'] = '';
-$db['default']['database'] = '';
+$db['default']['username'] = 'ichikawa';
+$db['default']['password'] = 'hogehoge';
+$db['default']['database'] = 'blog';
 $db['default']['dbdriver'] = 'mysql';
 $db['default']['dbprefix'] = '';
 $db['default']['pconnect'] = TRUE;

File application/controllers/blog.php

+<?php
+
+class Blog extends CI_Controller {
+
+	public function index()
+	{
+		echo 'Hello World!';
+	}
+
+	public function view($id) {
+
+		$this->load->model('blog_model');
+
+		if(!empty($id)){
+		$data['query'] = $this->blog_model->read_data($id);
+		}
+		$this->load->view('blog/view',$data);
+
+	}
+
+}

File application/models/blog_model.php

+<?php
+class Blog_model extends CI_Model {
+
+
+	function __construct()
+	{
+		parent::__construct();
+		$this->load->database();
+
+	}
+
+	function read_data($id)
+	{
+		$query = $this->db->get_where('posts', array('id' => $id), $limit=1);
+		return $query->result();
+
+	}
+
+
+}

File application/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>