mega-mega-mega kunena :woohoo: :woohoo: :woohoo: :woohoo: :woohoo:
Code:
<?php
class Blog extends CI_Controller {
function index($page = null)
{
//echo 123;
$data['title'] = "My Real Title";
$data['heading'] = "My Real Heading";
$this->load->model('Blogt');
$this->load->helper('form');
$this->load->helper('url');
//$this->load->library('javascript');
$this->load->helper('html');
$this->load->library('pagination');
$per_page = 5;
$config['base_url'] = 'http://codeigniter.oriander.org/blog/index/';
$config['total_rows'] = $this->Blogt->get_users_count();
$config['per_page'] = $per_page;
$config['num_links'] = 5;
$config['first_link'] = 'начало';
$config['last_link'] = 'конец';
$this->pagination->initialize($config);
$data['links'] = $this->pagination->create_links();
$data['query'] = $this->Blogt->get_users($page,$per_page);
$this->load->library('table');
$this->table->set_heading('Айдишник', 'Имя', 'Возраст', 'Картинка', 'Изменить', 'Удалить');
//$this->table->add_row(array('Fred', 'Blue', 'Small'));
foreach($data['query']->result() as $row)
{
$this->table->add_row($row->id, form_open('blog/update/').'<input type="hidden" value="'.$row->id.'" name="id"><input type="text" value="'.$row->name.'" name="name">', '<input type="text" value="'.$row->age.'" name="age">', '<img src="http://'.$_SERVER['HTTP_HOST'].'/uploads/'.$row->avatarka.'" />', '<input type="submit" name="update" value="Изменить">', '<input type="submit" name="delete" value="Удалить"></form>'); //Add each result row into table
}
$tmpl = array (
'table_open' => '<table border="0" cellpadding="4" cellspacing="0" style="border: 10px solid orange;">',
'heading_row_start' => '<tr style="border: 1px black dotted; background-color: lightgreen">',
'heading_row_end' => '</tr>',
'heading_cell_start' => '<th style="border: 1px white dotted; color:white; background-color: orange;">',
'heading_cell_end' => '</th>',
'row_start' => '<tr style="color:orange; font-weight:bold; background-color: white;">',
'row_end' => '</tr>',
'cell_start' => '<td>',
'cell_end' => '</td>',
'row_alt_start' => '<tr style="color:orange; background-color: #F8F8F8; font-weight:bold">',
'row_alt_end' => '</tr>',
'cell_alt_start' => '<td>',
'cell_alt_end' => '</td>',
'table_close' => '</table>'
);
$this->table->set_template($tmpl);
$this->table->set_caption('<b>Юзвери</b>');
$data['table'] = $this->table->generate();
$this->load->view('blogview', $data);
}
function update() {
//echo $_POST['name'];
$this->load->database();
$this->load->helper('url');
$this->load->library('form_validation');
if (isset($_POST['delete'])) {
$this->db->where('id', $_POST['id']);
$this->db->delete('users');
redirect('/blog/');
}
$this->form_validation->set_rules('name', 'Имя', 'trim|required|max_length[20]|xss_clean|htmlspecialchars|alpha');
$this->form_validation->set_rules('age', 'Возраст', 'trim|required|max_length[3]|numeric');
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
if ($this->form_validation->run() == FALSE)
{
//redirect('/blog/');
$this->index();
}
else
{
$this->db->where('id', $_POST['id']);
$this->db->update('users', array('name' => $_POST['name'], 'age' => $_POST['age']));
redirect('/blog/');
}
}
function insert_user()
{
$this->load->database();
$this->load->helper('url');
$this->load->library('form_validation');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '2000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
$this->upload->do_upload("userfile");
$imginf = $this->upload->data();
$config['image_library'] = 'gd2'; // выбираем библиотеку
$config['source_image'] = $imginf['full_path'];
//$config['create_thumb'] = TRUE; // ставим флаг создания эскиза
$config['maintain_ratio'] = TRUE; // сохранять пропорции
$config['width'] = 100; // и задаем размеры
$config['height'] = 100;
$this->load->library('image_lib', $config); // загружаем библиотеку
$this->image_lib->resize(); // и вызываем функцию
//unlink($imginf['full_path']);
$this->form_validation->set_rules('name', 'Имя', 'trim|required|max_length[20]|xss_clean|htmlspecialchars|alpha');
$this->form_validation->set_rules('age', 'Возраст', 'trim|required|max_length[3]|numeric');
$this->form_validation->set_error_delimiters('<span class="error">', '</span>');
if ($this->form_validation->run() == FALSE)
{
//redirect('/blog/');
$this->index();
}
else
{
$this->db->insert('users', array('name' => $_POST['name'], 'age' => $_POST['age'], 'avatarka' => $imginf['file_name']));
redirect('/blog/');
}
}
function comments()
{
echo 'Взгляни сюда!';
}
function shoes($sandals, $id)
{
echo $sandals;
echo $id;
}
}
?>