<?php
class Messages extends CI_Controller {
function index()
{
echo "Hello world (from controller).";
}
}
<?php
class Messages extends CI_Controller {
function index()
{
$data ['msg'] = "Hello world ";
$this->load->view('show', $data);
}
}
<?php
echo $msg;
echo "(from view).";
CREATE DATABASE msg;
CREATE TABLE `messages` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`body` text NOT NULL,
PRIMARY KEY (`id`)
);
INSERT INTO `messages` (`id`, `body`) VALUES
(1, 'Hello world !!! (from model)');
.
.
$autoload['libraries'] = array('database');
.
.
.
.
$db['default']['hostname'] = 'localhost';
$db['default']['username'] = 'root';
$db['default']['password'] = '123456';
$db['default']['database'] = 'msg';
$db['default']['dbdriver'] = 'mysql';
.
.
<?php
class Message extends CI_Model {
function get_msg()
{
$this->db->select();
$this->db->from('messages');
$query = $this->db->get();
return $query->result_array();
}
}
<?php
class Messages extends CI_Controller {
function index()
{
$this->load->model('message');
$data ['msgs'] = $this->message->get_msg();
$this->load->view('show', $data);
}
}
<?php
foreach ($msgs as $msg)
echo $msg['body'];
BY: Pejman Moghadam
TAG: php, codeigniter
DATE: 2013-01-27 19:36:53