0

my controller file code

public function viewAction(){
   $this->view->title="View Album";
}

my view file code

<?php echo $this->title;?>

but value can not access in view file warning given

warning

Warning: Creating default object from empty value

Bhargav Chudasama
  • 6,928
  • 5
  • 21
  • 39

1 Answers1

1

First this is not a Zend Framework issue. It is about core PHP.

It is an E_STRICT warning which may be enabled in your error_reporting ini settings if you are using PHP <= 5.3. But as of PHP 5.4 that error mode changed to E_WARNING. You should not disable E_WARNING warnings for the development environment.

So when are you getting that warning? You are getting this while you are trying to use an object which has not defined. Therefore, you have to define that object first, you should then use that property.

In ZF, you have ViewModel() object which has property overloading feature. To get rid of this warning you would use $title thus

public function viewAction()
{
    $view = new ViewModel();
    $view->title = "View Album";

    return $view;
}

And in your view script

<?php echo $this->title; ?>

For more details you may check out this problem and answer

unclexo
  • 3,691
  • 2
  • 18
  • 26