PHP code example of andrelohmann-silverstripe / bootstrap_orderable_frontend

1. Go to this page and download the library: Download andrelohmann-silverstripe/bootstrap_orderable_frontend 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/ */

    

andrelohmann-silverstripe / bootstrap_orderable_frontend example snippets


class MyController extends Controller {
	
	...

	public function orderableobjects(){
		
        $List = MyOrderableObject::get()->sort('Sort');
        $MyOrderableObjects = new OrderablePaginatedList($List, $this->request);
		$MyOrderableObjects->setPageLength(10)->setSortField('Sort');
        // if the sortable list is a many many relation
        // $MyOrderableObjects->setOwner($OwnerObject)->setManyMany('NAME_OF_MANY_MANY_RELATION');
		
		if($this->request->isAjax()) {
			return $this->customise(array(
                "Objects" => $MyOrderableObjects->process(), // process the ordering after OrderablePaginatedList has all information it needs (pageLength, SortField, Owner, ManyManyRelation)
				"URL" => $this->request->getURL(true) // add this for BackURL parameter
            ))->renderWith('OrderableObjectsList');
		}
		
		return $this->customise(new ArrayData(array(
			"Title" => "My Orderable Objects",
			"Objects" => $MyOrderableObjects,
			"URL" => $this->request->getURL(true) // add this for BackURL parameter
		)))->renderWith(
			array('Page_orderableobjects', $this->stat('template_main'), $this->stat('template'))
        );
	}