CodeIgniter Dinamik Navigasyon

2 Cevap php

Ben belgeler üzerinden CodeIgniter site ve tarama de demo videolarını bakıyorum ama onun benim ben elde edebilirsiniz nasıl dynamic navigation from one page to another, depending on user input belli değildir.

Örneğin ben "sayfa başarısız oturum açma" bir "başarı sayfa" ya da bir iletecek ya bir giriş formu var istiyorum.

Nerede bu işlevselliği koymak gerekir?

2 Cevap

Tamam, bu giriş örneğin gerekir böylece Form Helper, Form Validation Class ve URL Helper.

class Login extends MY_controller {

function index()
{
    $this->load->helper('url');
    $this->load->helper('form');
    $this->load->library('form_validation');

    // some simple rules
    $this->form_validation->set_rules('username', 'Username', 'required|alpha_dash|max_length[30]');
    $this->form_validation->set_rules('password', 'Password', 'required');
    if ($this->form_validation->run() == FALSE) {
        // This will be the default when the hit this controller/action, or if they submit the form and it does not validate against the rules set above.
        // Build your form here
        // Send it to a login view or something
    } else {
        // The form has been submitted, and validated
        // At this point you authenticate the user!!
        if ($userIsAuthenticated) {
            redirect('controller/action'); //anywhere you want them to go!
        } else {
            // not authenticated...in this case show the login view with "bad username/password" message
        }
    }
}

tl;dr

Sizin denetleyicisi mantığa dayalı diğer sayfalara kullanıcıya göndermek için URL Helper de yönlendirme () işlevini kullanın.

Genellikle bu tür Codeigniter gibi bir MVC çerçevede, dinamik navigasyon preform mantık denetleyicisi ikamet ediyorum.

Örnek: (php aromalı olarak yalancı-kod'da)

<?php
class Blog extends Controller {

    function login($username, $password)
    {
    	if ($username and $password are correct) {
                    $this->load->view('success');
                    return;
                }

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

Ben aslında CodeIgniter veya PHP kullanmak istemiyorum ama ben diğer dillerde MVC deneyime sahip. Nedeniyle de dil / çerçevesi yukarıdaki kodu kullanmayın lütfen benim acemilik ... Bu sadece bir örnek oldu. : D