开发者

An idea about login script

At the moment I think about login script. Idea - when you submit login and password, they checks into model and if login and password is correct, script shows a message about completed login process. But if I put in view echo $message; and I am at login page, kohana shows error - Undefined variable $message. But when I am at page, where the variable defined, all working. How to realize this idea.

EDIT!

class Controller_About extends Controller_Template {

public function action_index() {
    session_start();
    if (isset($_SESSION['lietotajvards'])) {

        if (!empty($_POST['virsraksts']) and !empty($_POST['saturs'])) {

            $name = Model::factory('index')->insert_names($_POST['virsraksts'], $_POST['saturs']);
            $result = $name;
            $this->template->site_name = Kohana::$config->load('common')->get('site_name');
            $this->template->site_description = Kohana::$config->load('common')->get('site_description');
            $this->template->page_title = 'About';
            $this->template->content = View::factory('about/about')->set('result', $result);
            $this->template->styles[] = 'index/index';
        } else {
            $this->template->site_name = Kohana::$config->load('common')->get('site_name');
            $this->template->site_description = Kohana::$config->load('common')->get('site_description');
            $this->template->page_title = 'About';
            $this->template->content = View::factory('about/about');
            $this->template->styles[] = 'index/index';
        }
    } else {
        if (!empty($_POST['lietotajvards']) and !empty($_POST['parole'])) {
            $user_model = Model::factory('index')->valide($_POST['lietotajvards'], md5($_POST['parole']));
            foreach ($user_model as $d) {
                if ($_POST['lietotajvards'] == $d['lietotajvards'] and md5($_POST['parole']) == $d['parole']) {
                    $_SESSION['lietotajvards'] = $_POST['lietotajvards'];
                    $this->template->content = View::factory('login/index')->set('message', 'Ielogošanās veiksmīga!');
                    echo '<meta http-equiv="refresh" content="5" url="http://127.0.0.1/about">';
                }
            }
        }
        $this->template->site_name = Kohana::$config->load('common')->get('site_name');
        $this->template->site_description = Kohana::$config->load('common')->get('site_description');
        $this->template->page_title = 'About';
        $this->template->cont开发者_高级运维ent = View::factory('login/index');
        $this->template->styles[] = 'index/index';
    }
}}

I have problem only with variable $message.

<?php echo $message; ?>
<form action="" method="post">
    <input type="text" name="lietotajvards" id="" />
    <input type="password" name="parole" id="" />
    <input type="submit" value="Nosūtīt datus!" />
</form>


The problem is you're setting the template content at the very end, which is overriding what you've previously set it to. Try changing

$this->template->content = View::factory('login/index')->set('message', 'Ielogošanās veiksmīga!');

to

$message = 'Ielogošanās veiksmīga!';

and then at the end change the view loading to

$this->template->content = View::factory('login/index')->bind('message',$message);

Using the bind method on the view will pass a null value to the view if the variable has not been set inside your controller.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜