php - Zend Framework view script, functions and variable scope -


I'm new to Zend Framework and am trying to understand it. In my visual script (index.phtml), I have this code that says:

  "; Print_r (this $); Echo "& lt; / pre & gt;"; $ String = ''; = "'. $ Element." ($ Empty-$ -> [$ element]) {$ string = $ string. & Lt; label class = "error"! '; Foreign currency ($- >-> ; Error [$ element] as $ error) {$ string = $ string. $ Error;} $ String = $ string. '& Lt; / label & gt;';} $ string return;} echo "& lt ; Pre & gt; "; print_r (this $); echo" & lt; / Pre> "getErrorString (" blah "); die ();  

It gives me:

  Fatal error: $ x When using the object X.   

on the index context in the object context, it seems that when you create a function within a scene, you lose $ $ this variable. I was searching around, and no one else could see me trying to get what I am doing (not very likely, maybe I'm looking for it wrong).

This is an A Can not see the reason why this function should be kept in a separate helper - especially because it is the only place that the function will ever be called.

Any idea will be highly appreciated.

Your function getErrorString () isn 'Zend_View- One object of the object is its scope and not up to $

The following code should work for you in index.phtml

  function getErrorString ($ viewObje Ct, $ element) {resonant "& lt; Pre & gt; "; print_r ($ viewObject); echo" & lt; / Pre> "$ String = ''; If (empty! $ ($ Object Object-> Error [$ element])) {$ string = $ string. & Lt; label class =" error " = "'. $ Element. "" Generation = "True" & gt; '; Foreach ($ viewObject-> Error [$ element] as $ error) {$ string = $ string $ Error; } $ String = $ string '& Lt; / Label & gt; '; } Return $ string; } Echo "prefix"; Print_r (this $); Echo "& lt; / pre & gt;"; GetErrorString ($ this, "blah"); Die ();  

Comments

Popular posts from this blog

Eclipse CDT variable colors in editor -

AJAX doesn't send POST query -

wpf - Custom Message Box Advice -