[eluser]Unknown[/eluser]
DB
Code:
CREATE TABLE `news_posts` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`author` varchar(30) NOT NULL,
`title` varchar(128) DEFAULT NULL,
`content` text,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=41 ;
controller
Code:
<?php
class Crudberita extends Controller {
function __construct()
{
parent::Controller();
$this->load->helper('url');
$this->load->model('crud_berita');
$this->load->scaffolding('posts');
$this->dx_auth->check_uri_permissions();
}
function index()
{
$data['current'] = 'crudberita';
$data['content'] = 'backend/crudberita_view';
$data['berita'] = $this->crud_berita->selectAll();
$this->load->view('container', $data);
}
function add()
{
if($_POST==NULL) {
$data['current'] = 'crudberita';
$data['content'] = 'backend/addberita_view';
$data['username'] = $this->dx_auth->get_username();
$this->load->view('container', $data);
}else {
$this->crud_berita->insert($_POST);
redirect('crud/crudberita/index');
}
}
model
Code:
class crud_berita extends Model {
function selectAll(){
return $this->db->get('news_posts')->result();
}
//function insert($set){
// $this->db->insert('news_posts', $set);
// }
function insert($id)
{
$data = array(
'id' => $this->input->post('id'),
'author' => ?????????, <--- I would like the author taken from the login username
'title' => $this->input->post('title'),
'content' => $this->input->post('content')
);
$this->db->insert('news_posts', $data);
}
addberita_view
Code:
<form action="" method="post">
<table>
<tr>
<th>id :</th>
<td><input name="id" /></td>
</tr>
<tr>
<th>author :</th>
<td>???????????</td> <---how to get author from the login username
</tr>
<tr>
<th>title :</th>
<td><input name="title" /></td>
</tr>
<tr>
<th>content :</th>
<td><textarea name="content"></textarea></td>
</tr>
<tr>
<th></th>
<td><input type="submit" value="Tambah" />
<input name="Reset" type="reset" value="Reset" /></td>
</tr>
</table>
</form>
for login i'm using DX_auth...I wanted to ask
- I want to get the author of the username to login, then added to the database automatically .. how to get it?? :question:
- what code I've made right? if any of what needs to be corrected?? :question: