Welcome Guest, Not a member yet? Register   Sign In
session in the view file
#1

[eluser]stalwart[/eluser]
This may be a stupid quersion but .....
How can i make this in CI in the view file
if (session_is_registered('username'){echo 'something';} else {form for login}
#2

[eluser]xwero[/eluser]
It's best you do this is a controller method and create two views.
#3

[eluser]stalwart[/eluser]
[quote author="xwero" date="1210104042"]It's best you do this is a controller method and create two views.[/quote]
but i am using template engine and it will be complecated
#4

[eluser]xwero[/eluser]
How would it be more complicated?
#5

[eluser]stalwart[/eluser]
[quote author="xwero" date="1210104469"]How would it be more complicated?[/quote]
I am using maintemplate so i have to make 2 main templates and in every output
if($this->session->userdata('username')){$maintemplate='logged';}
else {$maintemplate='notlogged';}
$this->template->load($maintemplate, 'view_file', $data);
#6

[eluser]Mirage[/eluser]
Just because you're making the test in the controller doesn't mean you have to split your template:
Code:
class SomeController extends Controller() {

    function somemethod() {
          // your code
          $loggedin=$this->session->userdata('loggedin');
          $this->load->view('mytemplate',array('loggedin'=>$loggedin);
    }

}

In the template:

Code:
<?php if($loggedin!==false):?>
Privileged Content here
<?php else: ?>
Login Form
<?php endif; ?>

Hope this helps.
#7

[eluser]stalwart[/eluser]
that works




Theme © iAndrew 2016 - Forum software by © MyBB