Part of the EllisLab Network
   
 
Native Session in CI1.5 - Problems with loading libraries (WAS: Native Session in CI1.5 - Wiki updated)
Posted: 05 November 2006 06:02 AM   [ Ignore ]  
Research Assistant
RankRankRank
Total Posts:  552
Joined  06-17-2006

I had to search the forums to find out how to get native sessions working in CI 1.5 so I updated the wiki. Hope this is ok with the author.

Hopefully it will save others a few mouseclicks!

 Signature 

CodeCrafter - Open Source Code Generation for CI

Profile
 
 
Posted: 06 November 2006 12:29 AM   [ Ignore ]   [ # 1 ]  
Grad Student
Avatar
Rank
Total Posts:  98
Joined  08-08-2006

Nice Crafter,
10x

 Signature 

Step into the future - Global PWD - http://www.globalpwd.com/

Profile
 
 
Posted: 07 November 2006 03:11 PM   [ Ignore ]   [ # 2 ]  
Lab Assistant
RankRank
Total Posts:  201
Joined  08-28-2006

Hi Guys,

Im getting the following error when trying the WIKI update.
Fatal error: Cannot redeclare class ci_session in ...\ci\system\libraries\Session.php on line 27
So I am getting an error from the core library ? I renamed the files and the class and constructor.

I also removed the brackets behind the class from the code in the WIKI. Any ideas ?

Thats the code from the WIKI. You should remove the brackets behind class Native_session ()

// class Native_session() {      // USE THE LINE BELOW INSTEAD
class CI_Session() {
  var $session_id_ttl = 360; // session id time to live (TTL) in seconds
  var $flash_key = ‘flash’; // prefix for “flash” variables (eg. flash:new:message)

//  function Native_session()    // USE THE LINE BELOW INSTEAD
  function CI_Session()
  {
      log_message(‘debug’, “Native_session Class Initialized”);
      $this->_sess_run();
  }

Profile
 
 
Posted: 08 November 2006 05:23 AM   [ Ignore ]   [ # 3 ]  
Lab Assistant
RankRank
Total Posts:  201
Joined  08-28-2006

link

Ok this is what my problem was. Would be nice if this could be fixed.

Greetings Jan

Profile
 
 
Posted: 08 November 2006 02:08 PM   [ Ignore ]   [ # 4 ]  
Research Assistant
RankRankRank
Total Posts:  552
Joined  06-17-2006

I’m also experiencing this problem, and its just not going away.

I’m loading the native sessiona in my application/library directory. This seems OK, until CI encounter another request to load(‘session’).

It seems that it’s loading the system/library/Session.php at that stage, which it should not be doing, since its’s being replaced by my application/library/Session.php

Look at the code from the loader class. It seems like the problem is around here.

$is_duplicate = FALSE;
                for (
$i = 1; $i < 3; $i++)
                
{
                        
// $path = ($i % 2) ? APPPATH : BASEPATH;
                        
$path = ($i == 1) ? APPPATH : BASEPATH;
                        
$fp = $path.'libraries/'.$class.EXT;

                        
// Does the file exist?  No?  Bummer...
                        
if ( ! file_exists($fp))
                        
{
                                
continue;
                        
}

                        
// Safety:  Was the class already loaded by a previous call?
                        
if (in_array($fp, $this->_ci_classes))
                        
{
                                $is_duplicate
= TRUE;
                                continue;
                        
}

                        
include($fp);
                        
$this->_ci_classes[] = $fp;
                        return
$this->_ci_init_class($class, '', $params);
                
}

OK. Let’s look at a few scenarious.
Scenario 1: No application/library AND No system/library/
Action: Code loops to top in first continue (because of file_exists() faliure.
Everrythinh OK here.


Scenario 1:  application/library AND system/library/ Our scenario
Action: First time in loop: Look for application/library/Session.php and loads that because of
        the include($fp) and then returns.
        At this stage, $fp, which is the FULL PATH is placed into the $this->ci_classes[] array.
        The function is exited without problem

        Next time it sees a load(session) call, the code segment is called again.
        First time in loop: Look for application/library/ file and sees that it ($fp) is loaded
        (that’s tha APPPATH stuff). Code loops to top in second continues (in_arrray().
        Next cycle in loop (bacuse of continue). Want’s to check the BASEPATH stuff.
        Gets to the file_exists: OK
        Gets to thein_array: NOT OK
        So what does it do. THAT’S RIGHT. IT LOADS BASEPATH library.


What do you think?

EDIT: My application is fairly complex is that there is some cross calling accross models/controllers.
I saolved this by removing all refrences to $this->load->library(). At least this helps in the maentime, although I still feel the above code shows a processing error.

 Signature 

CodeCrafter - Open Source Code Generation for CI

Profile
 
 
Posted: 09 November 2006 03:39 AM   [ Ignore ]   [ # 5 ]  
Grad Student
Avatar
Rank
Total Posts:  67
Joined  11-07-2006

This could be the why my sessions doesn’t work on php4 server, but all works in php5 test server?

 Signature 

cool hmm mmmmh…

Profile
 
 
Posted: 09 November 2006 01:19 PM   [ Ignore ]   [ # 6 ]  
Research Assistant
RankRankRank
Total Posts:  970
Joined  04-13-2006

This is probably way too late, but I wish the “native sessions” library could be called something else. “Native”, to me, means part of PHP. Confused? I will be.

Profile
 
 
Posted: 11 August 2008 04:48 AM   [ Ignore ]   [ # 7 ]  
Summer Student
Total Posts:  12
Joined  11-20-2007

Hi
I have to create more than one cotrollers.
Because currently, In my controller the code size is beyound 4000 lines.
How i put this number of functions in seperate files and again make call from main controller to this functions.

I have tried one solution for this, the files are:

1. made one base controller
/application/libraries/

class MY_Controller extends Controller {

function MY_Controller() {
parent::Controller();
}
function test_vinod($xyz)
{
echo “hi hello”;
echo $xyz;
}

}
2. for developer1

/application/libraries/

<?php

class devloper1 extends MY_Controller {

function devloper1() {
parent::MY_Controller();

}
function homepage()
{
echo “vinod”;
}
}

same as above i want to create more classes like developer2…..3,4,5
In which developer put his own functions

3. And finally my base controller from which i can call these functions from developers

<?php

class Welcome extends MY_Controller {

function Welcome()
{
parent::MY_Controller();


}

function index()
{
$this->test_vinod(’abc’);

$this->load->library(’devloper1’);
$this->devloper1->homepage();
// likely above statement can i load more libraries (developers)
// and call the functions
}

}

My question: is it way to make compact and clear code?

Thanks

 Signature 

livedress     
thesoko
How do u feel?

Profile
 
 
   
 
 
‹‹ CI 1.4.1 download      URI Routing question ››
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 719, on June 06, 2008 10:16 AM
Total Registered Members: 66413 Total Logged-in Users: 23
Total Topics: 84753 Total Anonymous Users: 1
Total Replies: 454814 Total Guests: 247
Total Posts: 539567    
Members ( View Memberlist )
Newest Members:  byrooNirCalexmuellerkizerdrixcaptainredmuffquinodligtharttechsivamDjordjesammozza