Jump to content

Recommended Posts

Working with somebody else's object-oriented PHP calendar system, I want to display the title of an event, but can't find the right syntax. Not that I particularly know what I'm doing....

 

The results of

print_r($this->output); 

begin with:

 

Array
(
    [0] => Calendar_EventInstance Object
        (
            [event] => Calendar_Event Object
                (
                    [__table] => event
                    [id] => 64
                    [title] => Summer Camp
                    [subtitle] => For High School Juniors
                    [othereventtype] => 
                    [description] => This camp helps young people gain programming skills (etc.) 

 

What's the correct syntax? I've tried:

<?php echo Calendar_Event->output->title; ?>
<?php echo Calendar_EventInstance::Calendar_Event::$this->output->title; ?>
<?php echo $this->output->title; ?>

 

As I said, I'm kind of in the dark here. I try to copy syntax from other parts of the code, but either the line or the page is blank.

 

Link to comment
https://forums.phpfreaks.com/topic/171214-syntax-for-displaying-oop-object-member/
Share on other sites

In OOP, you don't typically access a data member directly.  Publicly accessible members break encapsulation, which is one of the main points of OOP.  You need an accessor method (function).

 

Does this calender have a getTitle function, or something similar?

No, the code says:

  <!-- Main output for the view determined by determineView() and populated with run() -->
      
<?php Calendar::displayRegion($this->output); ?>

 

So I guess that's where I better look for the appropriate accessor method, or the appropriate model for writing my own. Thanks for the help.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.