XF 2.1 Having trouble passing a variable through

grantus

Active member
I'm working on my controller file and for testing purposes I just want to pass a variable through to my Entity so that it can be saved into the db 'filesize' column.

Code:
public function actionAdd()
    {
        $store = $this->em()->create('Path\To:Manage');
        $store->filesize = 12345;
        return $this->storeAddEdit($store);
    }

    public function actionEdit(ParameterBag $params)
    {
        $store = $this->assertStoreExists($params->store_id);
        $store->filesize = 12345;
        return $this->storeAddEdit($store);
    }

    protected function storeAddEdit(\Path\To\Entity\Manage $store)
    {
        $viewParams = [
            'store' => $store
        ];

        return $this->view('Path\To:Manage\Edit', 'manage_edit', $viewParams);
    }

I want to be able to get the 'filesize' value through. So far the only values I'm able to get are through my form or default values I have in my Entity structure. How can I pass through the 'filesize' value?
 
That code looks like it should work to me. You don't need to do anything special beyond setting the value (as you did) and then passing the entity to the other method.

Maybe filesize isn't an actual column you defined in your entity? Check if it's set after you tried to set it but before you pass it to the next method as a test?
 
That code looks like it should work to me. You don't need to do anything special beyond setting the value (as you did) and then passing the entity to the other method.

Maybe filesize isn't an actual column you defined in your entity? Check if it's set after you tried to set it but before you pass it to the next method as a test?
I just checked by echoing out $store->filesize and it shows 12345.

In my entity structure I have:
Code:
'filesize' => ['type' => self::UINT, 'default' => 0],

So that's why I'm stumped on this one.
 
I seemed to have fixed it. The other method storeSaveProcess:

Code:
protected function storeSaveProcess(\Path\To\Entity\Manage $store)
    {
        $input = $this->filter([
            'filename' => 'str'
        ]);

        $input['filesize'] = 45678;

        $form = $this->formAction();
        $form->basicEntitySave($store, $input);

        return $form;
    }

And it updates the filesize column correctly.
 
Top Bottom