Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.

Skripta za registraciju CodeIgniter

[es] :: PHP :: PHP za početnike :: Skripta za registraciju CodeIgniter

[ Pregleda: 1495 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Autor

Pretraga teme: Traži
Markiranje Štampanje RSS

BLACK_SWORD

Član broj: 212173
Poruke: 171
93.157.198.*

Sajt: www.artwebdizajn.com


+3 Profil

icon Skripta za registraciju CodeIgniter20.02.2012. u 19:28 - pre 148 meseci
Pozdrav!

Napravio sam skriptu za registraciju pomoću CodeIgniter framework/a

E sad pošto nisam dobro svatio MVC molio bi iskusne php programere da mi kažu dali sam ovo dobro uradio

Code:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User extends CI_Controller
{
    public function __construct()
    {
        parent::__construct();
        $this->load->model('User_model');
    }

    public function index()
    {
        $this->register();
    }

    public function register()
    {
        $data = array(
            'main_content' => 'user/register',
            'title'        => 'Registracija',
            'description'  => 'Stranica za registraciju.',
            'keywords'     => 'registracija, registuj, profil, korisnik'
        );

        $this->load->library('form_validation');
        $this->form_validation->set_rules('username', 'Korisničko ime', 'trim|required|min_length[2]|max_length[20]|alpha_dash|is_unique[users.username]');
        $this->form_validation->set_rules('email', 'E-mail adresa', 'trim|required|max_length[100]|valid_email|is_unique[users.email]');
        $this->form_validation->set_rules('email_conf', 'Potvrditi e-mail adresu', 'trim|required|matches[email]');
        $this->form_validation->set_rules('hide_email', 'Sakrij e-mail adresu', '');
        $this->form_validation->set_rules('password', 'Šifra', 'trim|required|min_length[6]|max_length[30]');
        $this->form_validation->set_rules('password_conf', 'Potvrditi šifru', 'trim|required|matches[password]');
        $this->form_validation->set_rules('gender', 'Izaberi spol', 'required');

        if ($this->form_validation->run() == FALSE)
        {
            $this->load->view('template', $data);
        }
        else
        {
            $this->load->helper('string');

            $insert = array(
                'username'        => $this->input->post('username'),
                'password'        => sha1($this->input->post('password')),
                'email'           => $this->input->post('email'),
                'hide_email'      => ($this->input->post('hide_email') ? 1 : 0),
                'date_registered' => date('Y-m-d H:i:s'),
                'ip_address'      => $this->input->ip_address(),
                'gender'          => ($this->input->post('gender') == 'male' ? 0 : 1),
                'validation_code' => random_string('alnum', 10)
            );

            $insert_id = $this->User_model->register_user($insert);

            $this->load->library('email');
            $this->email->from(config_item('site_email'), config_item('site_name'));
            $this->email->to($insert['email']);
            $this->email->subject('Aktivacijski e-mail');
            $this->email->message("Pozdrav!\nMolimo vas da kliknete na link:\n" . site_url('user/activate' . $insert_id . '/' . $insert['validation_code']));
            $this->email->send();

            $data = array(
                'main_content' => 'includes/notify',
                'heading'      => 'Registracija',
                'message'      => 'Uspiješno ste se registrovali, na vaš e-mail poslat je aktivacijski link.'
            );

            $this->load->view('template', $data);
        }
    }
}




model
Code:

<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class User_model extends CI_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function register_user($data)
    {
        $this->db->insert('users', $data);
        return $this->db->insert_id();
    }
}


Hvala na pomoći
 
Odgovor na temu

[es] :: PHP :: PHP za početnike :: Skripta za registraciju CodeIgniter

[ Pregleda: 1495 | Odgovora: 0 ] > FB > Twit

Postavi temu Odgovori

Navigacija
Lista poslednjih: 16, 32, 64, 128 poruka.