Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.0.1] The argument is not initialized or iterable() in phalcon/mvc/view.zep #12355

Closed
ss56806298 opened this issue Oct 24, 2016 · 13 comments
Closed

Comments

@ss56806298
Copy link

After I updated my phalcon from 2.0.X to 3.0.1,the error occured.And when i turned the version back,it runned normally.I'm not sured where the error happened.

$di = new FactoryDefault();

$di->set('view', function() use ($config) {

    $view = new View();

    return $view;
}, true);

Details

  • Phalcon version:3.0.1
  • PHP Version: 5.6.25
  • Operating System: WINDOWS
  • Installation type: DLL
  • Server: Apache
  • Other related info (Database, table schema): MYSQL 5.7.14
@Jurigag
Copy link
Contributor

Jurigag commented Oct 24, 2016

Just only this code is causing a problem ? Works fine for me. On php 7 and debian.

@stamster
Copy link
Contributor

stamster commented Oct 24, 2016

Just get rid of Windows (acting as an application server), it'll work fine on GNU/Linux (at least VM).

@sergeyklay
Copy link
Contributor

@ss56806298 Could you please provide detailed error log?

@ss56806298
Copy link
Author

ss56806298 commented Oct 25, 2016

@stamster
It's convenient to code on Windows.The error only occured when i updated the phalcon,so i guess the latest version may not suit for Windows.
@sergeyklay

#0 [internal function]: Phalcon\Mvc\View->_engineRender(Array, 'Login/check', true, true, NULL)
 #1 [internal function]: Phalcon\Mvc\View->render('Login', 'check', Array) 
#2 F:\wamp\www\original_server\index.php(22): Phalcon\Mvc\Application->handle() 
#3 {main}The argument is not initialized or iterable()

@Jurigag
Copy link
Contributor

Jurigag commented Oct 25, 2016

'Login/check' ? I don't see this in your code. Post whole script to reproduce, your code from OP is not reproducing a problem.

@SidRoberts
Copy link
Contributor

It could be that View::getViewsDirs() isn't returning an array, as is required in View::_engineRender(). Perhaps if View::setViewsDir() isn't used?

@ss56806298 if you haven't used View::setViewsDir(), could you try building Phalcon (using Zephir) from https://github.com/SidRoberts/cphalcon/tree/possible-fix-12355 to see if that fixes the problem?

@Jurigag
Copy link
Contributor

Jurigag commented Oct 25, 2016

If there would be script fully reproduce a problem then it would be good and we could now for sure what is causing it.

@ss56806298
Copy link
Author

ss56806298 commented Oct 26, 2016

@SidRoberts @Jurigag
I alreay solved the problem.Here is the the structure of my code.

$application = new \Phalcon\Mvc\application($di);
echo $application->handle()->getContent();

The variable $di just defined at the top of this page.

LoginController.php

class LoginController extends ControllerBase {
    public function checkAction() {
        try{
            $response = 1;
            $this->sendResponse($response);
        } catch(\Exception $e){
            throw $e;
        }
    }
}

ControllerBase.php

use Phalcon\Mvc\Controller;

class ControllerBase extends Controller{
    protected function sendResponse($response) {
        $this->response->setStatusCode(200, 'OK');
        $this->response->setHeader("Content-Type", "application/octet-stream");
        $this->response->setHeader("X-Content-Type-Options", "nosniff");
        $this->response->setContent($content);
        $this->response->send();
    }
}

ControllerBase.php after i modified

class ControllerBase extends Controller{
    protected function sendResponse($response) {
        $this->view->disable();
        $this->response->setStatusCode(200, 'OK');
        $this->response->setHeader("Content-Type", "application/octet-stream");
        $this->response->setHeader("X-Content-Type-Options", "nosniff");
        $this->response->setContent($content);
        $this->response->send();
    }
}

It seems that the lastest version of phalcon changed at the view.

@andrew-demb
Copy link
Contributor

I have encountered the same problem in Debian. As I found, the problem was in viewsDir. You can set it before append service view in DI or wait for an accept PR @SidRoberts.

@SidRoberts
Copy link
Contributor

Returning a response from the controller won't render a view (so you won't have to disable it):

class ControllerBase extends Controller
{
    protected function generateResponse($content)
    {
        $this->response->setStatusCode(200, 'OK');
        $this->response->setHeader("Content-Type", "application/octet-stream");
        $this->response->setHeader("X-Content-Type-Options", "nosniff");
        $this->response->setContent($content);

        return $this->response;
    }
}
class LoginController extends ControllerBase
{
    public function checkAction()
    {
        try {
            $response = 1;

            return $this->generateResponse($response);
        } catch (\Exception $e) {
            throw $e;
        }
    }
}

@Jurigag
Copy link
Contributor

Jurigag commented Oct 26, 2016

Exactly, just imho always return something from controller action.

@sergeyklay
Copy link
Contributor

@SidRoberts It is fixed in 3.0.x?

@SidRoberts
Copy link
Contributor

SidRoberts commented Oct 28, 2016

Yes (eca6ee1).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants