Link to home
Start Free TrialLog in
Avatar of Creini
Creini

asked on

Objects and session

Hi, I'm trying to create an object called Folder and in it I want to keep x Paper objects. Is it possible to keep these objects in a session? So I don't have to load the entire folder everytime I want to load view a page in the folder. I just want to load (from the db) when I'm getting a new Folder

My objects look like this:

Folder:
<?php
class Folder
{
    var $papers;            // Paper in the folder
        var $myIndex;
        var $myName;           // Category of the folder e.g Examples
        var $myDescription; //Describe whats in the folder
        var $myImage;            //Standard image of folder
   
     function Folder($name,$description,$image) {
          $this->myIndex      = 0;
          $this->myName     = $name;
          $this->myDescription = $description;
          $this->myImage     = $image;
     }  
   
   
    // Add a paper to the folder
    function addPaper ($paper) {
        $this->papers[$this->myIndex] = $paper;
        $this->myIndex++;
    }
   
    function getPaper ($index) {
         return $this->papers[$index];
    }
   
    function getName() {
         return $this->myName;
    }
   
    function getDescription() {
         return $this->myDescription;
    }
   
    function getImage() {
         return $this->myImage;
    }
   
    function getSize() {
         return $this->myIndex;
    }
}
?>


Paper:
<?php
class Paper
{
     
     var $myId;       // Id number in the database
     var $myFolder;     // Name of the folder it belongs to (e.g. News, Info)
     var     $myTitle;     // The title of the paper
     var     $myContent;     // The actual "article"
     var     $myImage;     // Name of the image associated with the paper
         
     function Paper($id,$folder,$title,$content,$image) {
         
          $this->myId          =     $id;
          $this->myFolder     =     $folder;
          $this->myTitle     =     $title;
          $this->myContent=     $content;
          $this->myImage     =     $image;
     }
         
     function getId() {
          return $this->myId;
     }
     
     function getFolder() {
          return $this->myFolder;
     }
     
     function getTitle() {
          return $this->myTitle;
     }
     
     function getContent() {
          return $this->myContent;
     }
     
     function getImage() {
          return $this->myImage;
     }
}
?>

/Mattias
ASKER CERTIFIED SOLUTION
Avatar of bljak
bljak

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of waygood
waygood

You must also load the class definition prior to starting the session otherwise php will not understand the data structure when it loads it into memory.

include_once('classes.inc');
session_start();