CodeIgniter ile ana sayfa oluşturmak

0 Cevap php

Nasıl CodeIgniter ile bir ana sayfa oluşturabilir?

Bu sayfa, vb kayıt, giriş gibi birkaç bağlantılar içermelidir

Ben bir giriş ekranı oluşturmak için bir tut izledi. Ama sadece bu amaç için CodeIgniter yaptı. Bu benim bahsettiğim site:

http://tutsmore.com/programming/php/10-minutes-with-codeigniter-creating-login-form/

Yani temelde ne im çalışıyorum sadece bir giriş formunun daha fazla şeyler için CodeIgniter'ı kullandık.

Benim try routes.php ben bu ayarları:

$route['default_controller'] = "mainpage";
$route['login'] = "login";

Benim mainpage.php dosyası:

class Mainpage extends Controller
{
    function Welcome()
    {
        parent::Controller();
    }

    function index()
    {

        $this->load->view('mainpage.html');
    }
}

Mainpage.html:

<HTML>

<HEAD>
<TITLE></TITLE>
<style>
      a.1{text-decoration:none}
      a.2{text-decoration:underline}
</style>

</HEAD>

<BODY>

     <a class="2" href="login.php">login</a>

</BODY>
</HTML>

Login.php tam olarak ben bu yazı için bağlantıyı sağladığı web sitesinde benziyor:

Class Login extends Controller
{
    function Login()
    {
        parent::Controller();
    }

    function Index()
    {
        $this->load->view('login_form');
    }

    function verify()
    {
        if($this->input->post('username'))
        { //checks whether the form has been submited
            $this->load->library('form_validation');//Loads the form_validation library class
            $rules = array(
                array('field'=>'username','label'=>'username','rules'=>'required'),
                array('field'=>'password','label'=>'password','rules'=>'required')
            );//validation rules

            $this->form_validation->set_rules($rules);//Setting the validation rules inside the validation function
            if($this->form_validation->run() == FALSE)
            { //Checks whether the form is properly sent
                $this->load->view('login_form'); //If validation fails load the <b style="color: black; background-color: rgb(153, 255, 153);">login</b> form again
            }
            else
            {
                $result = $this->common->login($this->input->post('username'),$this->input->post('password')); //If validation success then call the <b style="color: black; background-color: rgb(153, 255, 153);">login</b> function inside the common model and pass the arguments
                if($result)
                { //if <b style="color: black; background-color: rgb(153, 255, 153);">login</b> success
                    foreach($result as $row)
                    {
                        $this->session->set_userdata(array('logged_in'=>true,'id'=>$row->id,'username'=>$row->username)); //set the data into the session
                    }

                    $this->load->view('success'); //Load the success page
                }
            else
            { // If validation fails.
                    $data = array();
                    $data['error'] = 'Incorrect Username/Password'; //<b style="color: black; background-color: rgb(160, 255, 255);">create</b> the error string
                    $this->load->view('login_form', $data); //Load the <b style="color: black; background-color: rgb(153, 255, 153);">login</b> page and pass the error message
                }
            }
        }
        else
        {
            $this->load->view('login_form');
        }
    }
}

Ne i adamlar eksik?

0 Cevap