Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Oct 2010
    Location
    Florence, MS
    Posts
    486
    Thanks
    10
    Thanked 33 Times in 32 Posts

    CodeIgniter Controller issue

    Okay, I have a controller called Site.
    PHP Code:
    <?php

    class Site extends CI_Controller
    {
        public 
    $page_data;
        function 
    __construct()
        {
            
    parent::__construct();
            
    $this->load->model('forum_model');
            
    $this->load->model('article_model');
            
    $this->load->model('category_model');
            
    $this->load->library('pagination');
            
    $this->load->model('membership_model');
            
    $this->load->library('form_validation');
            
    $this->page_data['is_logged_in'] = $this->_is_logged_in();
        }
        function 
    index()
        {
            
    $this->page_data['categories'] = $this->category_model->getAll();
            
    $this->page_data['recentPosts'] = $this->forum_model->getNewestPosts();
            
    $this->page_data['posts'] = $this->article_model->getRecentArticle();
            
    $this->page_data['main_content'] = array('beginL','posts_view','endLbegR','search_box','categories','archive_menu','index');
            
    $this->page_data['keywords'] = "Index, main page";
            
    $this->load->view('includes/template'$this->page_data);
        }
        function 
    view_archive(){    
            
    $month $this->uri->segment(3);
            
    $year $this->uri->segment(4);
            
    $date $year.'-'.$month;
            
    $this->page_data['categories'] = $this->category_model->getAll();
            
    $this->page_data['recentPosts'] = $this->forum_model->getNewestPosts();
            
    $this->page_data['posts'] = $this->article_model->getRecentArticle();
            
    $this->page_data['keywords'] = "archive page";
            
    $this->page_data['posts'] = $this->article_model->getArticlesByMonthYear($date);
            
    $this->page_data['main_content'] = array('beginL','posts_view','endLbegR','search_box','categories','archive_menu','index');
            
    $this->load->view('includes/template'$this->page_data); 
        }
        
        function 
    _is_logged_in()
        {
            
    $is_logged_in $this->session->userdata('is_logged_in');
            
            if(!isset(
    $is_logged_in)|| $is_logged_in != true)
            {
                return 
    false;
            }else {
                return 
    true;    
            }
        }
        function 
    login($err=false)
        {
            if(
    $this->_is_logged_in()){
                
    redirect('site/index');        
            }
            
    $this->page_data['keywords'] = 'login page';
            
    $this->page_data['main_content'] = array('login_form');
            
    $this->page_data['error'] = $err;
            
    $this->load->view('includes/template'$this->page_data);
        }
        function 
    validate_credentials()
        {
            
    $query=$this->membership_model->validate();
            if(
    $query)
            {
                
    $data = array(
                    
    'username' => $this->input->post('username'),
                    
    'is_logged_in' => true
                
    );    
                
    $this->session->set_userdata($data);
                
    redirect('site/index');
            } else
            {
                
    $this->login('Unable to log you in');    
            }
        }
        function 
    signup()
        {
            
    $this->page_data['keywords'] = 'signup';
            
    $this->page_data['main_content'] = array('signup_form');    
            
    $this->load->view('includes/template'$this->page_data);
        }
        function 
    create_member()
        {
            
    // field name, error message, validation rules
            
    $this->form_validation->set_rules('email''Email''trim|required|valid_email');
            
    $this->form_validation->set_rules('username''Username''trim|required|min_length[4]');
            
    $this->form_validation->set_rules('password''Password''trim|required|min_length[4]|max_length[32]');
            
    $this->form_validation->set_rules('password2''Password Confirmation''trim|required|matches[password]');
            if(
    $this->form_validation->run()== FALSE)
            {
                
    $this->signup();
            }else{
                if(
    $query $this->membership_model->create_member())
                {
                    
    $this->page_data['keywords'] = 'signup, success';
                    
    $this->page_data['main_content'] = array('signup_successful');
                    
    $this->load->view('includes/template'$this->page_data);
                } else {
                    
    $this->signup();    
                }
            }
        }
        function 
    logout()  
        {      
            
    $this->session->sess_destroy();  
            
    redirect('site/index');
        } 
    }
    I have a view called header that has my menu in it:
    PHP Code:
    <!DOCTYPE html>
    <head>
    <meta name="description" content="A roleplaying magazine and forum for the roleplays you desire." />
    <meta name="keywords" content="<?php echo $keywords?>" />
    <meta name="author" content="Chris Hickingbottom" />
    <meta charset="UTF-8" />
    <title>My Roleplay Magazine</title>
    <link href="<?php echo base_url(); ?>css/templatemo_style.css" rel="stylesheet" type="text/css" />
    <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript" charset="utf-8"></script>
    </head>
    <body>
        <div id="templatemo_container">
            <div id="templatemo_header">
                <div id="templatemo_logo">
                    <div id="templatemo_logo_text">
                        My Roleplay Magazine
                       </div>
                </div>
                <div id="templatemo_menu_section">
                    <ul>
                        <li><a href="<?php echo base_url(); ?>" class="home">Home</a></li>
                        <?php if($is_logged_in){?>
                        <li><a href="<?php echo site_url();?>/site/logout" class="about">Logout</a></li>
                        <?php } else {?>
                        <li><a href="<?php echo site_url();?>/site/login" class="about">Login</a></li>
                        <li><a href="<?php echo site_url();?>/site/signup" class="archive">Sign Up</a></li>
                        <?php }?>
                        
                        <li><a href="" class=""></a></li>
                    </ul>
                </div>
            </div>
            <!--  End Of Header  -->
              <div id="templatemo_content_area">
    On the two methods, validate_credentials and create_members, the error is_logged_in is undefined variable keeps popping up. The variable apparently isn't being defined, yet its defined in every one of my calls. Any ideas what is going on??
    Notice: If you post a problem and it gets fixed, please remember to go back and place it as solved. ;)
    I always recommend the HEAD First series of books for learning a new coding language. ^_^

  • #2
    Senior Coder
    Join Date
    Feb 2011
    Location
    Your Monitor
    Posts
    4,474
    Thanks
    63
    Thanked 537 Times in 524 Posts
    You've not posted the exact message which would be helpful as it usually contains line numbers.

    You might also want to look into debug_backtrace() to get the function call stack.
    I can't really think of anything to write here now...


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •