0

There are different modules and all of them returns ViewModel in the actions. But somehow, ViewModel acting weird a bit in one of the modules.

I am saying;

$view = new ViewModel(array('data' => $someContent));
$view->setTemplate('a valid path to template');

return $view;

and getting an empty page.

If I put an exit() statement at the end of related template like

<!DOCTYPE html>
<html>
    ...
</html>
<?php exit(); ?>

I can get the expected output because script ends there but I lost the output otherwise.

If I say *var_dump($view)*, I can see that the $view is an instance of Zend\View\Model\ViewModel.

There is no error, just an empty output and even the notice warnings are visible. So, it doesn't throw any exception, error, warning, notice etc.

To remind that again, it just happens in a specific module but that module are not different the others actually.

I am not a ZF guru and I am working on someone else's codes, so please give me a start point to able to find that problem.

Thanks in advance.

edit : I have an extra info;

It works if I use JsonModel instead of ViewModel and as you may know, JsonModel extends the ViewModel.

5
  • as exit() helped, output buffering comes to mind. If it happens on a specific module, that module might do something with output buffering? Commented Mar 7, 2013 at 12:27
  • You're right but I couldn't find anything related with buffering or anything to affect ViewModel. Commented Mar 7, 2013 at 12:29
  • raise warnings and notices to the highest level in your php.ini then, enable error logging and look for warnings / notices / errors by following the log. Commented Mar 7, 2013 at 12:36
  • Does that module, or more specifically, the view template for it, use any custom view helpers. I've found during development that a borked view helper can silently obfuscate rendering of content. Commented Mar 7, 2013 at 12:36
  • There are nothing in the template actually. I've put some text into the template to test it and it doesn't change anything. Commented Mar 7, 2013 at 12:40

1 Answer 1

1

Since you have not posted your controller action properly , this is the guess what I could do on your problem .

In Zend framework 2 there are various types of controllers from which you will be extending your controllers with in your modules .

for example in case if you extend your controller from AbstractActionController your view will be returned properly .

So the problem here is your other modules have controllers extending AbstractActionController . This module which is not returning your view properly might not be extending it . Instead it might be extending other controllers such as restfulcontrollers

You should also check in module.php file of your module to check whether you have any strategies eg json strategy applied on bootstrap for this module from module.config.php .

eg.

return array(
    'view_manager' => array(
        'strategies' => array(
           'ViewJsonStrategy',
        ),
    ),
)

Also you have check your module.config.php file whether you have proper specification for your viewmanager to your template .

eg .

'view_manager' => array(
        'template_path_stack' => array(
            'album' => __DIR__ . '/../view',
        ),
    ),

Hope this helps .

Sign up to request clarification or add additional context in comments.

1 Comment

I know my post has not much details but I can't give any because of the project and preparing dummy ones would consume too much time which I don't actually. I am sorry about it. But your post really helped me and found the problem. First, there was no layout definition for the module. Second, the layout file for the module was empty. I simply put a directive to print content and voila. I believe there is no harm to choose your message as answer. Thanks a lot.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.