How to call an Express object from a block controller?

Permalink
Hello,

I use an Express object made from the C5.8 dashboard.
I did a custom block and I would like to get my Express object in my block controller to pass it to my view.

I try to do this in the view() method but it doesn't work :-/ Should I add something in the xml file ?

Any idea what is wrong in my code ? Thx

This is my block controller:

```
<?php namespace Application\Block\Subsides;

use Concrete\Core\Asset\AssetList;
use Concrete\Core\Block\BlockController;
use Express;
use Concrete\Core\Express\EntryList;

defined('C5_EXECUTE') or die('Access Denied.');

class Controller extends BlockController
{

protected $btTable = 'btSubsides';
protected $btExportTables = ['btSubsides'];
protected $btInterfaceWidth = '900';
protected $btInterfaceHeight = '650';
protected $btWrapperClass = 'ccm-ui';
protected $btCacheBlockRecord = true;
protected $btCacheBlockOutput = true;
protected $btCacheBlockOutputOnPost = true;
protected $btCacheBlockOutputForRegisteredUsers = true;
protected $btCacheBlockOutputLifetime = 0;



protected $btDefaultSet = 'express'; // basic, navigation, form, express, social, multimedia

private $uniqueID;

public function getBlockTypeName() {
return t('Subsides');
}

public function getBlockTypeDescription() {
return t('Ce block liste les financements par année.');
}




public function on_start() {

// Unique identifier
$this->uniqueID = $this->app->make('helper/validation/identifier')->getString(18);
$this->set('uniqueID', $this->uniqueID);

// Année (subsideyear) options
$subsideyear_options = [];
$subsideyear_options[] = '----';
$subsideyear_options['2020'] = h(t('2020'));
$subsideyear_options['2021'] = h(t('2021'));
$subsideyear_options['2022'] = h(t('2022'));
$subsideyear_options['2023'] = h(t('2023'));
$subsideyear_options['2024'] = h(t('2024'));
$subsideyear_options['2025'] = h(t('2025'));
$subsideyear_options['2026'] = h(t('2026'));
$subsideyear_options['2027'] = h(t('2027'));
$subsideyear_options['2028'] = h(t('2028'));
$subsideyear_options['2029'] = h(t('2029'));
$subsideyear_options['2030'] = h(t('2030'));
$subsideyear_options['2031'] = h(t('2031'));
$subsideyear_options['2032'] = h(t('2032'));
$subsideyear_options['2033'] = h(t('2033'));
$subsideyear_options['2034'] = h(t('2034'));
$subsideyear_options['2035'] = h(t('2035'));

$this->set('subsideyear_options', $subsideyear_options);

}

public function add() {

$this->addEdit();

}

public function edit() {

$this->addEdit();

}

public function addEdit() {

// Load form.css
$al = AssetList::getInstance();
$al->register('css', 'subsides/form', 'blocks/subsides/css_files/form.css', [], false);
$this->requireAsset('css', 'subsides/form');

// Make $app available in view
$this->set('app', $this->app);

}

public function view() {

// Make $app available in view
$this->set('app', $this->app);

// Get subside Express object
$entity = Express::getObjectByHandle('cofinancement');
$list = new EntryList($entity);
var_dump($list);
/*$subside = $list->getResults();
$this->set('subside', $subside);*/

}

public function save($args) {

// Basic fields
$args['subsideyear'] = trim($args['subsideyear']);

parent::save($args);

}

public function duplicate($newBlockID) {

parent::duplicate($newBlockID);

}

public function delete() {

}

public function validate($args) {

$error = $this->app->make('helper/validation/error');

// Required fields
$requiredFields = [];
$requiredFields['subsideyear'] = t('Année');

foreach ($requiredFields as $requiredFieldHandle => $requiredFieldLabel) {

if (empty($args[$requiredFieldHandle])) {
$error->add(t('Field "%s" is required.', $requiredFieldLabel));
}

}

// Required fields - Links
$requiredLinkFields = [];

foreach ($requiredLinkFields as $requiredLinkFieldHandle => $requiredLinkFieldLabel) {

$errorCounter = 0;
$errorCounter += empty($args[$requiredLinkFieldHandle.'_link_type']) ? 1 : 0;
$errorCounter += ($args[$requiredLinkFieldHandle.'_link_type']=='link_from_sitemap' AND empty($args[$requiredLinkFieldHandle.'_link_from_sitemap'])) ? 1 : 0;
$errorCounter += ($args[$requiredLinkFieldHandle.'_link_type']=='link_from_file_manager' AND empty($args[$requiredLinkFieldHandle.'_link_from_file_manager'])) ? 1 : 0;
$errorCounter += ($args[$requiredLinkFieldHandle.'_link_type']=='external_link' AND empty($args[$requiredLinkFieldHandle.'_external_link'])) ? 1 : 0;

if ($errorCounter > 0) {
$error->add(t('Field "%s" is required.', $requiredLinkFieldLabel));
}

}

return $error;

}

public function composer() {

$this->edit();

}

public function scrapbook() {

$this->edit();

}

}
```

View Replies:
houston5948 replied on at Permalink Reply
If no rejected value is provided, next will be called with a default Error object the string 'route' ), Express regards the current request as being an error and will example uses a try...catch block to catch errors in the asynchronous code.