I'm getting something now ... nope. I can't read your mind.
What Kohana version are you using? Can you provide some code samples?
Don't you have your crystall ball? (joke :P)
version 3.x
home view includes controllers (I use there UTF-8 coding header if it will help)
login controller has 2 method - first one to display login's view, and the second one to run after user submits a form:
public function action_index() {
$this->template_content = new View('login');
}
public function run_model() {
$results = new Model_Login;
$count = $results->check(); // numbers of rows that match given login and password
$row = $results->checkArray(); // if $count is not zero, $row is the array with fields from the matched row
if ($count > 0) {
Session::instance()->set('id', $row['ID']); // session with user id
Session::instance()->set('zalogowany', $row['Login']); // session with user login
$this->template->login = $row['Login']; // var to display login after logging in
$this->template_content = new View('Done/login_done');
} else {
$this->template_content = new View('Errors/login_error');
}
}
and login view, which is the form with login and password fields. In login's model I check if a row with login and password given in the form exists. If it does, in controller I create sessions, if not I display error (is it actually a good way to display errors?). I don't know if it will work because I haven't validated this code yet, I still get this A session had already been started - ignoring session_start() error. Is there something wrong in this code that causes this error?
Your PHP is probably set to automatically start the session. You should disable this in php.ini, or call session_destroy() before starting the session.
How do I use mysqli_real_escape_string() function in 3.x version?
By using Database::quote.
How do I do this?
$query = DB::query(Database::SELECT, 'SELECT * FROM Users WHERE Login = :login and Password = :password')
->param(':login', $_POST['login'])
->param(':password', $this->passwordHash($_POST['password']))
->quote($_POST['password'])
->execute();
This gives an error Call to undefined method Database_Query::quote(). Where should I use Database::quote? The example in guide is $db->quote(NULL);, what's $db variable?
You dont need to use Database::quote() on paramenter you pass to Database_Query::param() of Database_Query::bind().
Database_Query::param() and Database_Query::bind() store the value/reference you pass to them. Database_Query::execute() fills $db (if necessary) and passes it to Database_Query::compile(). Then Database_Query::compile() will use Database::quote() on the parameters.
Oh, thanks for help ;] One more little question...
My controller extends template controller. It has public template variable that loades a form view.
public $template = 'login';
public function action_index() {
$this->template->content = new View('login');
}
public function action_controll() {
$results = new Model_Login;
$row = $results->browse();
if ($row == 'error') {
$this->template->content = new View('Errors/login_error');
} else {
$this->template->login = $row; // var to display login after logging in
$this->template->content = new View('Done/login_done');
}
}
First, view form is loading in action_index() method. Next I type login and password, and the form redirect me to the above controller's action_controll() method. If the model's return value is error, it should to include error's view, otherwise it should to include a view file that shows everything was successful. However it always shows view file login. What should I change so that this form is not included after submitting it?
Nevermind, I solved it. How can I pass a get value through making new view file in controller? In controller I get login and I want to display it in view file. It should to look like this:
$this->template->content = new View('Done/login_done?login='.$row);
But it doesn't word. How do I do this?
It looks like you're new here. If you want to get involved, click one of these buttons!