thetuningspoon Posted November 24, 2015 Share Posted November 24, 2015 I'm trying out extending the Page class to add methods to pages of a particular template. I've discovered that when I try to use a magic method to access one of my fields from a method within the class (i.e. $this->title) it returns nothing. I am used to being able to call $event->object->title from within a hook, so I expected this to be even simpler when using a custom class. I can output $this->id okay, but not any of my custom fields. What am I missing here? Here is my code: <?php class PodcastEpisode extends Page { public function getFileUrl() { return $this->podcast_file ? $this->podcast_file->httpUrl : $this->podcast_file_url; } public function getFileSize() { return $this->podcast_file ? $this->podcast_file->filesize : $this->podcast_file_size; } public function getFileExt() { return $this->podcast_file ? $this->podcast_file->ext : pathinfo($this->podcast_file_url, PATHINFO_EXTENSION); } public function getFileType() { $fileType = ''; $fileTypes = array( 'audio/mpeg' => 'mp3', 'audio/x-m4a' => 'm4a', 'video/mp4' => 'mp4', 'video/x-m4v' => 'm4v', 'video/quicktime' => 'mov', 'application/pdf' => 'pdf', 'document/x-epub' => 'epub' ); foreach($fileTypes as $key => $value) { if(strcasecmp($value, $this->getfileExt()) == 0) { //If the value matches the file extension $fileType = $key; //Set $fileType to the corresponding File Type string from the $fileTypes array break; } } return $fileType; } } Link to comment Share on other sites More sharing options...
Wanze Posted November 24, 2015 Share Posted November 24, 2015 Hi, Not sure why it shouldn't work, did you try getting a field or value with $this->get('title') ? Link to comment Share on other sites More sharing options...
thetuningspoon Posted November 24, 2015 Author Share Posted November 24, 2015 I did try $this->get() as well. I can try again. I'm glad to know that it should work, at least. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now