Cakepdf: undefined method Cake\View\ViewBuilder::options()

Hello,

I’m using CakePHP 4 and cakepdf to generate pdf since it is compatible with CakePHP 4. However, I got error when loading the view. the public function view is as follows:

	public function view($id = null)
{
        $user = $this->Users->get($id);
        $this->viewBuilder()->options([
            'pdfConfig' => [
                'orientation' => 'portrait',
                'filename' => 'User_' . $id
            ]
        ]);
        $this->set('user', $user);
}

Error: Call to undefined method Cake\View\ViewBuilder::options()

I’ve been using the same code for CakePHP 3 and it works. How to make it compatible with cakephp 4. Thanks

check your Deprecation warning may be change in method naming convention

in the migration note: https://book.cakephp.org/4/en/appendices/4-0-migration-guide.html stated that:

The _serialize , _jsonOptions and _jsonp special view variables of JsonView are now deprecated. Instead you should use viewBuilder()->setOption($optionName, $optionValue) to set these options.

I try:

public function view($id = null)
{
$user = $this->Users->get($id);
$this->viewBuilder()->setOptions([
‘pdfConfig’ => [
‘orientation’ => ‘portrait’,
‘download’ => true
]
]);
$this->set(‘user’, $user);

Error: Cannot convert value of type string to integer

Why this happen and how can i solve this. Thanks

It’ll be because you’re passing a string where it should be an integer. It’s hard for us to guess where. It should tell you a specific file and line number, go look at that code and see what it’s trying to reference there.

Did you had any luck with this?