?
Solved

Objects and session

Posted on 2003-03-29
2
Medium Priority
?
225 Views
Last Modified: 2008-03-06
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
0
Comment
Question by:Creini
2 Comments
 
LVL 4

Accepted Solution

by:
bljak earned 300 total points
ID: 8232330
yes, start each page with
session_start();

$lastYear = new Folder;
//func to execute
//and then
$folder = $lastYear->papers;
session_register("folder");
//or use ths if session_register() doesn't work (i expirienced problems with php 4.2.2 i think
$_SESSION["folder"] = $folder;

thats it, do not forget to have session_start(); on each next page

hope this helped some further
//bljak
0
 
LVL 9

Expert Comment

by:waygood
ID: 8237729
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();
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses

615 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question