Results 1 to 5 of 5
Like Tree2Likes
  • 1 Post By misson
  • 1 Post By mephis

Thread: [PHP] CodeIgniter Help

  1. #1
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    456

    [PHP] CodeIgniter Help

    I'm making a page render class for a thing i'm making but when I go to do $this->session->userdata('username'); it says I can't access it.

    the PageRender class is extending the controller so it can load view files for the template_header and template_footer. I also get the error above when I try to access the template parser class hence why i'm having it extend the Controller class instead. could someone help?

    PageRender:
    Code:
    <?php
    if (!defined('BASEPATH')){
        exit('No direct script access allowed'); 
    }
    class PageRender extends Controller{
        function PageRender(){
            parent::Controller();
        }
        function generateHeader($loggedUser){
            //$user = ($this->session->userdata('username')) ? $this->session->userdata('username') : 'Guest';
            $headerData = array(
                'pageHeading' => 'Nevux Ability Boards (1.4.6 Devel)',
                'cssFiles' => array("style.css"),
                'jsFiles' => array("jquery"),
                'metaData' => array(),
                'User' => $loggedUser,
                'RenderInstance' => $this
            );
            $this->load->view('templates/layout_header', $headerData);
        }
        function incorporateTemplate($templateData){
            
        }
        function generateFooter(){
            
        }
        function loadItems($type = null, $fileName = null, $metaKey = null, $metaData = null){
            
        }
    }
    ?>

  2. #2
    misson is offline x10 Spammer
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,573

    Re: [PHP] CodeIgniter Help

    Quote Originally Posted by Shadow121 View Post
    I'm making a page render class for a thing i'm making but when I go to do $this->session->userdata('username'); it says I can't access it.
    What's "it"? What's the actual error you're getting?

    As it says in the CodeIgniter user guide, make sure you load the session library, either via auto-loading or in the PageRender constructor:
    PHP Code:
        function PageRender(){
            
    parent::Controller();
            
    $this->load->library('session');
        } 

  3. #3
    Shadow121's Avatar
    Shadow121 is offline x10 Lieutenant
    Join Date
    Jul 2006
    Location
    Centerville
    Posts
    456

    Re: [PHP] CodeIgniter Help

    Yes, it being the error.

    And the library is auto-loaded because I can access it in the boards controller. but instead of putting it in EVERY controller I want to declare the $User one time which is when it goes to generate the header area.

  4. #4
    misson is offline x10 Spammer
    Join Date
    Mar 2008
    Location
    Libertatia
    Posts
    2,573

    Re: [PHP] CodeIgniter Help

    Quote Originally Posted by Shadow121 View Post
    Yes, it being the error.
    That doesn't actually answer my questions. Again, what is the exact error you're getting? What is "it" that can't be accessed? For instance, if "it" is $this->session, then the session library isn't being loaded. If "it" is $this->session->userdata, then the CodeIgniter installation is probably messed up.

    When asking a question, please describe the problem concisely, including the software environment and precise error messages (you posted a minimal test case, which is very helpful). It's extremely hard to solve an issue if we don't know exactly what is going wrong.

    The best thing you can do for yourself is install XDebug on a test server and use Eclipse PDT to debug the application. Then you can examine variables &c. at the exact point the PHP script is failing.
    karimirt47 likes this.

  5. #5
    mephis's Avatar
    mephis is offline x10Hosting Member
    Join Date
    Aug 2008
    Location
    London, UK
    Posts
    39

    Re: [PHP] CodeIgniter Help

    Quote Originally Posted by Shadow121 View Post
    And the library is auto-loaded because I can access it in the boards controller.
    Assuming the session library is loaded and you're only having issues accessing the session variable "username": do you have cookies enabled on your test browser? CodeIgniter's developers have decided to use cookies to store CI's session variables (don't ask me why!). I personally prefer to replace their original session library with one that uses native PHP sessions (you can find it on their forums/wiki)
    dinomirt96 likes this.

Similar Threads

  1. [php] Function Efficiency
    By taekwondokid42 in forum Scripts, 3rd Party Apps, and Programming
    Replies: 3
    Last Post: 04-06-2008, 10:28 AM
  2. [php] Cookies
    By taekwondokid42 in forum Scripts, 3rd Party Apps, and Programming
    Replies: 2
    Last Post: 04-03-2008, 04:27 PM
  3. [PHP] Wait for a while then redirect
    By Shadow121 in forum Scripts, 3rd Party Apps, and Programming
    Replies: 3
    Last Post: 02-19-2008, 02:04 PM
  4. [PHP] Dynamic Includes Tutorial
    By Bryon in forum Tutorials
    Replies: 3
    Last Post: 12-16-2005, 01:34 PM

Posting Permissions

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