Skip to content

Instantly share code, notes, and snippets.

@jpalala
Last active July 30, 2024 03:10
Show Gist options
  • Save jpalala/10598363 to your computer and use it in GitHub Desktop.
Save jpalala/10598363 to your computer and use it in GitHub Desktop.
Author_Glu - a simple class to output author html example
<?php
class Author_Glu {
public $html;
public function __construct($obj) {
$this->html = '<div class="author-name" data-detail="' . substr(0,150,$obj->bio) . '">' . $obj->firstname . ' ' . $obj->lastname . '</div>';
}
public function __toString() {
try {
// Note that the property needs to exist
// on the class, or therefore the exception
// will be thrown
return (string) $this->html;;
} catch (Exception $exception) {
// Optionally you can var_dump (or use laravel dd())
var_dump($exception->getMessage());
return '';
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment