Go Back   CodingForums.com > :: Server side development > PHP

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-13-2012, 05:44 PM   PM User | #1
Chris Hick
Regular Coder

 
Join Date: Oct 2010
Location: Florence, MS
Posts: 476
Thanks: 10
Thanked 33 Times in 32 Posts
Chris Hick is an unknown quantity at this point
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. ^_^
Chris Hick is offline   Reply With Quote
Old 09-13-2012, 06:21 PM   PM User | #2
tangoforce
Senior Coder

 
tangoforce's Avatar
 
Join Date: Feb 2011
Location: Your Monitor
Posts: 3,667
Thanks: 46
Thanked 456 Times in 444 Posts
tangoforce will become famous soon enoughtangoforce will become famous soon enough
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.
__________________
Please don't be rude: Put your php code in [php][/php] tags. It is a sticky topic at the top of the forum and it HELPS us to HELP YOU!
TIP: Coding styles and $end errors :::::::::: TIP: Warning: Cannot modify header information - headers already sent :::::::::: TIP: Quotes / Parse error: syntax error, unexpected T_..
PHP Code:
//Please don't use this for your form processing:
if (isset($_POST['submit']))
//Internet explorer has a bug and does not always send the submit value. 
Explanation: The IE if(isset($_POST['submit'])) bug explained.
tangoforce is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 12:55 AM.


Advertisement
Log in to turn off these ads.