Welcome Guest, Not a member yet? Register   Sign In
basic stuff passing vars from controller to view
#1

[eluser]alebenson[/eluser]
i have this view file:

admin_view.php
Code:
<html><head><title>Admin</title></head>
<body>

<h1>Admin</h1>
<h2 style="color:#f00;">&lt;?=$this->validation->error_string;?&gt;</h2>
<h3 style="color:#0f0;">&lt;?=$error;?&gt;</h3>
&lt;form action="&lt;?=site_url("admin/"); ?&gt;" method="post" enctype="multipart/form-data"&gt;
<h5><label for="usuario">Usuario</label></h5>
    &lt;input type="text" name="usuario" id="usuario" value="&lt;?=$this-&gt;validation->usuario;?&gt;" />
    
<h5><label for="password">Password</label></h5>
    &lt;input type="password" name="password" id="password" value="" /&gt;
<br /><br />
    &lt;input name="sumbit" type="submit" value="enviar" id="sumbit" /&gt;
&lt;/form&gt;

&lt;/body&gt;&lt;/html&gt;

the h2 shows the error from the validation library
the h3 is for another kind of errors that I want to show

so one of the controllers (admin.php) have this function

Code:
function perfil()
{
    $this->load->helper('url');
    $this->load->library('session');        

    if ($this->session->userdata('USUARIO') != FALSE)
    {
    echo 'im logged';
    }
    else
    {
    $data = array('error' => 'Enter your User and Pass');
    redirect('admin/', $data);
    }
}

if you try to enter the /admin/perfil/ and you are not logged this thing send you to the form... and i want to show that text, but i dont know why it doesnt work!!

i know this is basic stuff
i read the load->view user guide and copy paste the code there and works fine, but here it seem not to work
#2

[eluser]tonanbarbarian[/eluser]
you cannot pass data via the redirect
redirect sends a response back to the users browser tell it to go to a different page.
you should pass data to a view to display it
#3

[eluser]alebenson[/eluser]
yes.. woking now... but 2 things going wrong so
first the URI shows as admin/perfil/ , does not update to just admin/, because of the view and not on the redirect

and &lt;?=$this->validation->usuario;?&gt; from the admin_view.php show me an error because im not passing anything

i guess the question i have to ask is diferente
the thing i want to do here is that if someone try to get admin/perfil and is not logged
the funcion send it to the admin/ with an error message

but im thinkg of giving up on the error message and use the redirect

what do you suggest?
#4

[eluser]tonanbarbarian[/eluser]
I am not sure what you are saying the issue is
but i recommend you sit down and read the User Guide all the way through and also maybe view the tutorial videos as well




Theme © iAndrew 2016 - Forum software by © MyBB