XF 2.0 Converting XF1.1 to 2.0 ResponseView issue

KozmoK

Active member
Hello,

I am converting an external auth addon. I have most of it working now execpt the response.

In XF1.1 I did something like this in the PublicController:
Code:
             if ($version != "31")
                {
                        return $this->responseView('GeekPoint_ExternalAuth_ViewPublic_Version');
                }

And it would do a Raw Render from this file:

Code:
<?php

class GeekPoint_ExternalAuth_ViewPublic_Version extends XenForo_ViewPublic_Base
{
    public function renderRaw()
    {
        return '-VERSION';
    }
}


So how can I do a RenderRaw direct from the new ControllerPublic I made?


EDIT:

I can get it to work now, but its saving it as a file now. I want it output /render directly to the redirect.
 
Last edited:
There's more to the original code you mentioned than you've provided as the raw renderer wouldn't normally be triggered without other actions. But I'd recommend that you look at how attachments are served as it sounds similar.
 
Yeah I was looking at the Attachments, that is how I got it to work somewhat now.

The problem its, its saving the file like a attachment. Its not displaying a new page.

Here is my controller code:

Code:
<?php

namespace GeekPoint\ExternalAuth\Pub\Controller;

use XF\Pub\Controller\AbstractController;
use XF\Mvc\ParameterBag;

class ExternalAuth extends AbstractController
{
        public function actionIndex()
        {
                $this->setResponseType('raw');
                $this->assertPostOnly();

                $input = $this->filter([
                        'vb_login_username' => 'str',
                        'vb_login_password' => 'str'
                ]);

                $ip = $this->request->getIp();
                $loginService = $this->service('XF:User\Login', $input['vb_login_username'], $ip);
                $user = $loginService->validate($input['vb_login_password'], $error);

                if (!$user)
                {
                         return $this->view('GeekPoint\ExternalAuth\Pub\View\Test\Auth');
                }
        }
}


Here is my View Extend:

Code:
<?php

namespace GeekPoint\ExternalAuth\Pub\View\Test;

use XF\Mvc\View;

class Auth extends \XF\Mvc\View
{
        public function renderRaw()
        {
                $this->response->header('Content-Type: text/plain');  //I Was trying to set this so it wouldnt save as new file
                return 'ERROR';
        }
}
 
That's not how the header() method in the response object works -- the header name and the value are separate parameters.
 
I got it working! Thanks Mike!

here is the fix (response->contentType)

Code:
 public function renderRaw()
        {
                $this->response->contentType('text/plain');
                return 'ERROR';
        }
 
Top Bottom