coderex
coderex

Reputation: 27845

Extbase view variable not getting

/**
 * New post form
 * @param  \Vendor\My\Domain\Model\Post|null $newPost New post
 * @return void
 * @dontvalidate $newPost
 */
public function newAction(\Vendor\My\Domain\Model\Post $newPost = NULL) {
    $this->view->assign('test', 'hello');
    $this->view->assign('categoryList', $this->categoryRepository->findAllByBlog(0));
    $this->view->assign('postObject', $newPost);
}

public function editAction() {
    $this->view->assign('categoryList', $this->categoryRepository->findAllByBlog(0));
    $postObject = $this->postRepository->findOneByUid($this->request->getArgument('id'));
    $this->view->assign('postObject', $postObject);

}

this is my script and my problem is that I have a categoryList array, its is only getting in edit view. I want to use that category list on newaction. When I tried to foreach that array in new action view file it is getting empty. and i can get it after saving the postObject. Any idea about this particular problem? and variable test from newaction also not visible in the newAction Template file.

Am using Typo3 7.6.11

Upvotes: 0

Views: 1040

Answers (2)

cephei_vv
cephei_vv

Reputation: 220

If a $this->***Repository method returns NULL, it may be that the repository had no StoragePid defined.

Make sure both newAction and editAction have the same storagePid defined in TypoScript or your Backend Plugin Settings (Flexform).

The TypoScript for this would look something like this:

plugin.tx_extension.persistence.storagePid = 100

Upvotes: 0

Claus Due
Claus Due

Reputation: 4261

Declare arguments you want to receive, as arguments for your controller action. Reference this argument name correctly in Fluid templates when you build links to your controller action. Do not access arguments from the Request directly. Add correct PDPdoc comments for it, too.

Basically: do the correct thing with your arguments instead of bypassing the framework. This advise applies to anything you do in Extbase.

NB: New and Edit actions should never, ever share the same template (this further indicates you bypass the framework's expected behavior). Create and New, yes. But not New and Edit. If necessary, put the form fields in a partial and the form itself in separate templates so you can control the action building and object/object-name setup correctly.

Upvotes: 3

Related Questions