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);
Just only this code is causing a problem ? Works fine for me. On php 7 and debian.
Just get rid of Windows (acting as an application server), it'll work fine on GNU/Linux (at least VM).
@ss56806298 Could you please provide detailed error log?
@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()
'Login/check' ? I don't see this in your code. Post whole script to reproduce, your code from OP is not reproducing a problem.
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?
If there would be script fully reproduce a problem then it would be good and we could now for sure what is causing it.
@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.
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.
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;
}
}
}
Exactly, just imho always return something from controller action.
@SidRoberts It is fixed in 3.0.x?
Yes (https://github.com/phalcon/cphalcon/pull/12362/commits/eca6ee1be614a2d3408a2485b91bd940cf099702).
Most helpful comment
Returning a response from the controller won't render a view (so you won't have to disable it):