Announcement

Collapse
No announcement yet.

MivaScript equivalent of print_r?

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    MivaScript equivalent of print_r?

    Does anyone have a code snippet that will print out an array structure for easy viewing, similar to print_r in PHP? miva_array_deserialize is NOT cutting it ;)

    Thanks,
    Susan
    Susan Petracco
    NetBlazon

    1.866.400.2444

    _____________________________________________

    Like us on Facebook

    #2
    Re: MivaScript equivalent of print_r?

    Hey Susan -

    Not that i'm aware. What is missing is miva_array_serialize which you are looking for?
    Brennan Heyde
    VP Product
    Miva, Inc.
    [email protected]
    https://www.miva.com

    Comment


      #3
      Re: MivaScript equivalent of print_r?

      Nicely formatted output with indents for sub-arrays and so forth, when it's a large structure. Just a nice-to-have, not a requirement.
      Susan Petracco
      NetBlazon

      1.866.400.2444

      _____________________________________________

      Like us on Facebook

      Comment


        #4
        Re: MivaScript equivalent of print_r?

        I'll pass the suggestion along to our development team. I can see how that would be a nice feature when working with large structures / arrays.
        Brennan Heyde
        VP Product
        Miva, Inc.
        [email protected]
        https://www.miva.com

        Comment


          #5
          Re: MivaScript equivalent of print_r?

          Thanks Brennan :)
          Susan Petracco
          NetBlazon

          1.866.400.2444

          _____________________________________________

          Like us on Facebook

          Comment


            #6
            Re: MivaScript equivalent of print_r?

            Not Pretty, but here's what we use:

            Code:
            <MvCOMMENT> ======================= DebugStructure ======================= 
            	Purpose: send structure to screen
            	Input: structure
            	Output:
            	Last change: 01/15/2013 gdc - renamed function name
            </MvCOMMENT>
            <MvFUNCTION NAME="DebugStructure" PARAMETERS="structure" STANDARDOUTPUTLEVEL="">
            
            	<MvASSIGN NAME="l.debug_array" VALUE="{ miva_array_serialize(l.structure) }">
            	<MvASSIGN NAME="l.debug_use_break" VALUE="1">
            	<MvASSIGN NAME="l.debug_pos" VALUE="1">
            	<MvASSIGN NAME="l.debug_text" VALUE="{ gettoken(l.debug_array, ',', l.debug_pos) }">
            
            	<MvEVAL EXPR="{ '<div style="background-color:white; color:black;"><ul>' }">
            
            	<MvWHILE EXPR="{ l.debug_text }">
            		<MvIF EXPR="{ l.debug_use_break }">
            			<MvASSIGN NAME="l.debug_num" VALUE="{ len(l.debug_text) - (len(glosub(l.debug_text, ':', '')))}">
            			<MvASSIGN NAME="l.debug_count" VALUE="0">
            			<MvASSIGN NAME="l.debug_test" VALUE="">
            
            			<MvWHILE EXPR="{ l.debug_count LT l.debug_num }">
            				<MvASSIGN NAME="l.debug_count" VALUE="{ l.debug_count + 1 }">
            				<MvASSIGN NAME="l.debug_test" VALUE="{ l.debug_test $ gettoken(l.debug_text, ':', l.debug_num) }">
            			</MvWHILE>
            			
            			<MvIF EXPR="{ l.debug_test NE l.debug_previous }">
            				<MvEVAL EXPR="<br>">
            			</MvIF>
            			<MvASSIGN NAME="l.debug_previous" VALUE="{ l.debug_test }">
            		</MvIF>
            
            	    <MvIF EXPR="{ asciichar(60) IN decodeattribute(l.debug_text) }">
            	    	<MvEVAL EXPR="{ '<pre>' $ encodeentities(decodeattribute(l.debug_text)) $ '</pre>' }">
            		<MvELSE>
            			<MvEVAL EXPR="{ decodeattribute(l.debug_text) $ '<br>' }">
            		</MvIF>
            		
            		<MvASSIGN NAME="l.debug_pos" VALUE="{ l.debug_pos + 1 }">
            		<MvASSIGN NAME="l.debug_text" VALUE="{ gettoken(l.debug_array, ',', l.debug_pos) }">
            	</MvWHILE>
            
            	<MvEVAL EXPR="{ '<br></div></ul>' }">
            
            </MvFUNCTION>
            Bruce Golub
            Phosphor Media - "Your Success is our Business"

            Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
            phosphormedia.com

            Comment


              #7
              Re: MivaScript equivalent of print_r?

              Thank you Bruce, I will give that a shot.
              Susan Petracco
              NetBlazon

              1.866.400.2444

              _____________________________________________

              Like us on Facebook

              Comment


                #8
                Re: MivaScript equivalent of print_r?

                This one doesn't indent, but it will put one element on each line if you use "<br/>" as the delimiter. I use this for debugging just about every module I write.
                Code:
                <MvFUNCTION NAME="Structure" PARAMETERS="data, delim" STANDARDOUTPUTLEVEL="">
                	<MvASSIGN NAME="l.v" VALUE="{ miva_array_serialize(l.data) }">
                	<MvIF EXPR="{ substring(l.v, 1, 1) EQ '=' }">
                		<MvFUNCRETURN VALUE="{ l.data }">
                	</MvIF>
                	<MvWHILE EXPR="{ gettoken(l.v, ',', l.n + 1) }">
                		<MvASSIGN NAME="l.n" VALUE="{ l.n + 1 }">
                		<MvASSIGN NAME="l.fld" VALUE="{ gettoken(l.v, ',', l.n) }">
                		<MvASSIGN NAME="l.fnam" VALUE="{ gettoken(l.fld, '=', 1) }">
                		<MvASSIGN NAME="l.fval" VALUE="{ decodeattribute(gettoken(l.fld, '=', 2)) }">
                		<MvASSIGN NAME="l.ret" VALUE="{ l.ret $ l.fnam $ '=' $ l.fval }">
                		<MvIF EXPR="{ gettoken(l.v, ',', l.n + 1) }">
                			<MvASSIGN NAME="l.ret" VALUE="{ l.ret $ l.delim }">
                		</MvIF>
                	</MvWHILE>
                	<MvFUNCRETURN VALUE="{ l.ret }">
                </MvFUNCTION>
                Last edited by Kent Multer; 03-25-14, 08:33 AM.
                Kent Multer
                Magic Metal Productions
                http://TheMagicM.com
                * Web developer/designer
                * E-commerce and Miva
                * Author, The Official Miva Web Scripting Book -- available on-line:
                http://www.amazon.com/exec/obidos/IS...icmetalproducA

                Comment


                  #9
                  Re: MivaScript equivalent of print_r?

                  We usually just use <MvEVAL EXPR = "{ glosub( miva_array_serialize( l.var ), ',', '<br>' ) }">, but we'll consider adding something a little more visually friendly in a future version.

                  Comment


                    #10
                    Re: MivaScript equivalent of print_r?

                    Bruce,

                    I like this output, but I have a couple comments.
                    1) It would be amazing if it was recursive. I tried it a structure within a structure and it spaces nicely, but it would be cool if the substructure got it's own <ul>.
                    2) The last line should be "</ul><br /></div>" to close everything in the right order.
                    3) Need to add in the <li></li> tags when outputting the values.

                    Think I'll play around with this and see what I can come up with.
                    Last edited by Scott McCollough; 03-27-14, 10:31 AM.

                    Comment


                      #11
                      Re: MivaScript equivalent of print_r?

                      Thanks Scott. Yea, its an internal tool and everytime we notice what's broken, we're too busy solving another problem<g>.
                      Bruce Golub
                      Phosphor Media - "Your Success is our Business"

                      Improve Your Customer Service | Get MORE Customers | Edit CSS/Javascript/HTML Easily | Make Your Site Faster | Get Indexed by Google | Free Modules | Follow Us on Facebook
                      phosphormedia.com

                      Comment


                        #12
                        Re: MivaScript equivalent of print_r?

                        What I do is, convert the object to json and just print it out to the browser console. Works like a charm.

                        Comment

                        Working...
                        X