PHP code example of dynamic / viewable-dataobject

1. Go to this page and download the library: Download dynamic/viewable-dataobject library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

dynamic / viewable-dataobject example snippets



	
use Dynamic\ViewableDataObject\VDOInterfaces\ViewableDataObjectInterface;
	
class MyDataObject extends DataObject implements ViewableDataObjectInterface
{
	public function getParentPage()
	{
		return MyDisplayPage::get()->first();
	}
	
	public function getViewAction()
	{
		return 'myobject';
	}
}



use SilverStripe\Control\HTTPRequest;
use SilverStripe\View\ArrayData;

class MyDisplayPageController extends \PageController
{
    public function myobject(HTTPRequest $request)
    {
        $urlSegment = $request->latestParam('ID');
	
        if (!$object = MyDataObject::get()->filter('URLSegment', $urlSegment)->first()) {
            return $this->httpError(404, "The object you're looking for doesn't seem to be here.");
        }
	
        return $this->customise(new ArrayData([
            'Object' => $object,
            'Title' => $object->Title,
            'MetaTags' => $object->MetaTags(false),
            'Breadcrumbs' => $object->Breadcrumbs(),
        ]));
    }
} 	



use SilverStripe\Control\HTTPRequest;

class MyDisplayPageController extends \PageController
{
    public function myobject(HTTPRequest $request)
    {
        $urlSegment = $request->latestParam('ID');
	
        if (!$object = MyDataObject::get()->filter('URLSegment', $urlSegment)->first()) {
            return $this->httpError(404, "The object you're looking for doesn't seem to be here.");
        }
		
        return $this->renderWithLayout([
            MyDataObject::class,
            MyDisplayPage::class,
        ], [
        	'Object' => $object,
            'Title' => $object->Title,
            'MetaTags' => $object->MetaTags(false),
            'Breadcrumbs' => $object->Breadcrumbs(),
        ]);
    }
}