Welcome Guest, Not a member yet? Register   Sign In
Couple Questions
#1

[eluser]mfroseth[/eluser]
Very new to CI and have a couple questions. I've created a folder inside views called "admin" and I have my html template, however the stylesheet and images could not be generated for some reason, Is there a special way to do this? I tried "../" "./" etc...

Also, I used a tutorial for creating a login section that I have redirected to my views/admin_panel (which is the html template I was just referring to) and I want to create a function for displaying the username.

How do I go about outputting the function that I create? Are there special calls? Inside the function I've pulled the username from the database using the user_id session and matching it with the user_id in the database. But I am unsure as to how I can display this using the function I created.

Any help would be greatly appreciated.

Thanks
#2

[eluser]the_unforgiven[/eluser]
When linking to css, js always use syntax like this:

Code:
<link rel="stylesheet" href="<?php echo base_url(); ?>css/main.css" type="text/css" />

As for the rest you are talking about post your code in
Code:
'[code]
'[/code] tags and someone will answer you.
#3

[eluser]mfroseth[/eluser]
[quote author="the_unforgiven" date="1337803533"]When linking to css, js always use syntax like this:

Code:
<link rel="stylesheet" href="<?php echo base_url(); ?>css/main.css" type="text/css" />

As for the rest you are talking about post your code in
Code:
'[code]
'[/code] tags and someone will answer you.[/quote]
Thank you very much! The base URL is what I set in config.php correct? So anything after that would be the actual directory (say: view/admin/style.css) right?

I haven't finished creating this function, so it probably doesn't even work as expected right now. I'm still trying to grasp this whole system but here is the login function and displayUsername function:

Code:
public function displayUsername ($username) {
  
  $user_id = $this->session->userdata('user_id');
  
  $query = "SELECT username FROM users WHERE id = $user_id";
  
  $result = $this->db->query($query, array($username));
}

public function login()
{
  $this->form_validation->set_rules('username', 'Username', 'required|trim|max_length[50]|xss_clean');
  $this->form_validation->set_rules('password', 'Password', 'required|trim|max_length[200]|xss_clean');
  

  if($this->form_validation->run() == FALSE)
     {
  
   $this->load->view('view_login');
  }
  else
  {
   // process their input and login
  
   $username= $this->input->post('username');
   $password= $this->input->post('password');
  
   $user_id = $this->User_model->check_login($username,$password);
  
   if (!$user_id)
   {
    // login failed error
    
    $this->session->set_flashdata('login_error', TRUE);
    
    echo("Log In Failed");
    
         redirect('user/login', 'refresh');
   }
  
   else
  
   {
    //log in
    
    $this->session->set_userdata('logged_in',TRUE);
    $this->session->set_userdata('user_id', $user_id);  
    
         redirect('user/admin_panel', 'refresh');      
   }
  
  }
#4

[eluser]the_unforgiven[/eluser]
in your config file
Code:
$config['base_url'] = '';
should already there just fill out the empty space like so:

Code:
$config['base_url'] = 'http://localhost/yoursite';  or just type your domain if your doing it l;ive

An you functions look fine to me
#5

[eluser]mfroseth[/eluser]
[quote author="the_unforgiven" date="1337805311"]in your config file
Code:
$config['base_url'] = '';
should already there just fill out the empty space like so:

Code:
$config['base_url'] = 'http://localhost/yoursite';  or just type your domain if your doing it l;ive

An you functions look fine to me [/quote]

Thanks, but how do I output the function for displaying the username of who is logged in on a view page? Is there a special way to do this with CI?

Thanks
#6

[eluser]mfroseth[/eluser]
Edit: nevermind, had wrong URL. Wouldn't work if I had these stored inside the application/views folder.
#7

[eluser]mfroseth[/eluser]
Anybody?
#8

[eluser]Samus[/eluser]
[quote author="mfroseth" date="1337864716"]Anybody? [/quote]
store it in a session and then retrieve it?
#9

[eluser]mfroseth[/eluser]
[quote author="Samus" date="1337866174"][quote author="mfroseth" date="1337864716"]Anybody? [/quote]
store it in a session and then retrieve it?[/quote]
This is my code, however I can't get it to display for the life of me:

Code:
function displayUsername ()

  {
  
  $user_id = $this->session->userdata('user_id');
  
  $query = $this->db->get_where('users', array('id' => '$user_id'));
  
  foreach ($query->result() as $row)
  {
   echo $row->username;
  }
    
      
  }
#10

[eluser]mfroseth[/eluser]
[quote author="mfroseth" date="1337868534"][quote author="Samus" date="1337866174"][quote author="mfroseth" date="1337864716"]Anybody? [/quote]
store it in a session and then retrieve it?[/quote]
This is my code, however I can't get it to display for the life of me:

Code:
function displayUsername ()

  {
  
  $user_id = $this->session->userdata('user_id');
  
  $query = $this->db->get_where('users', array('id' => '$user_id'));
  
  foreach ($query->result() as $row)
  {
   echo $row->username;
  }
    
      
  }
[/quote]

Gah, stupid typos. Had $user_id in single quotes for my $query.




Theme © iAndrew 2016 - Forum software by © MyBB