In a custom extbase extension, I need to call a show action, passing it another value than uid
(this is a continuation of Use other than primary key as RealURL id_field).
As the value "other than uid" is not resolved, it results in the exception http://wiki.typo3.org/Exception/CMS/1297759968
EDIT: here's the current working (but ugly) Controller code:
/**
* ItemController
*/
class ItemController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController {
/**
* itemRepository
*
* @var \STUBR\Weiterbildung\Domain\Repository\ItemRepository
* @inject
*/
protected $itemRepository = NULL;
/**
* action list
*
* @return void
*/
public function listAction(\STUBR\Weiterbildung\Domain\Model\Item $item=null) {
if (!empty(\TYPO3\CMS\Core\Utility\GeneralUtility::_GET('tx_weiterbildung_pi1'))){
$this->forward('show');
}
$items = $this->itemRepository->findAll();
$this->view->assign('items', $items);
}
/**
* action show
*
* @param \STUBR\Weiterbildung\Domain\Model\Item $item
* @return void
*/
public function showAction(\STUBR\Weiterbildung\Domain\Model\Item $item=null) {
$tx_weiterbildung_pi1_get = \TYPO3\CMS\Core\Utility\GeneralUtility::_GET('tx_weiterbildung_pi1');
if (!empty($tx_weiterbildung_pi1_get)){
$dfid = intval($tx_weiterbildung_pi1_get['durchfuehrungId']);
}
$items = $this->itemRepository->findByDurchfuehrungId($dfid);
// helpful:
//\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($item);
$this->view->assign('item', $items[0]);
}
}
PS here are the 5 lines that could be used in the Repository if the magical method wouldn't work:
//public function findByDurchfuehrungId($dfid) {
// $query = $this->createQuery();
// $query->matching($query->equals('durchfuehrungId', $dfid));
// return $query->execute();
//}
Yes, when you're using actions with model binding in param it will always look for object by field defined as ID - in our case it's always
uid
, but remember, that you do not need to bind model automatically, as you can retrive it yourself.Most probably you remember, that some time ago I advised to use
<f:link.page additionalParams="{originalUid:myObj.originalUid}"Click here</f:link.page>
instead of<f:link.action...>
In that case your show action would look like this:
Where
findByOriginalUid
should work magically without declaration, but even if it doesn't it's just matter of 5 lines in the repo ;)Other sample
According to the code you pasted I'd use it rather like this, in this case
listAction
gets a role of dispatcher for whole plugin:Your finder should also
getFirst()
object if possible: