We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 5340
    • 1,624 Posts
    HI,

    According to bob’s guides this should work

    <?php

    $chunk = $modx->getObject(’modChunk’, array(’name’ => ’SponsorEload’ ));
    var_dump($chunk);

    ?>

    The above code crashes my server. Am I missing something?
      • 4172
      • 5,888 Posts
      you can try

      <?php
      $chunk = $modx->getObject('modChunk', array('name' => 'SponsorEload' ));
      var_dump($chunk->toArray());
      ?>


      or

      <?php
      $chunk = $modx->getObject('modChunk', array('name' => 'SponsorEload' ));
      print_r($chunk);
      ?>
        -------------------------------

        you can buy me a beer, if you like MIGX

        http://webcmsolutions.de/migx.html

        Thanks!
        • 5340
        • 1,624 Posts
        Thx smiley

        Any ideas why it does that. It’s the first time it happens to me.

        I always used var_dump without problems until now.
          • 2611
          • 394 Posts
          Hey cipa,

          It doesn’t crash the server but the browser. If you don’t do ->toArray() you will get a very very large object which is hundreds (maybe thousands) of lines long (i think it includes much of the XPDO class and MODX core class) because it all inherits eachother.

          I hope this makes sence, but i have the same when i get any object and var_dump it smiley the text is just to big for the browser to display normally.
            Follow me on twitter: @b03tz
            Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
            CodeMaster
            • 5340
            • 1,624 Posts
            It makes now. I’ve seen the size of the dump.

            BTW, do you know how to get the value of a TV given the name of the TV and ID of the document.

            I’m struggling with:

            $parentId = $modx->resource->get('parent');
            $tv = $modx->getCollection('modTemplateVar',array(
                'name' => 'ArticlesBanner',
                'id' => $parentId
            ));
            print_r($tv);


            I think ID does not exist. Is there a place I can find what I need?


              • 2611
              • 394 Posts
              You should check out the file:

              core/model/schema/modx.mysql.schema.xml

              Search for templateVar and there you can see what you can use...
              Here’s a little exerpt:

                  <object class="modTemplateVar" table="site_tmplvars" extends="modElement">
                      <field key="type" dbtype="varchar" precision="20" phptype="string" null="false" default="" />
                      <field key="name" dbtype="varchar" precision="50" phptype="string" null="false" default="" index="unique" />
                      <field key="caption" dbtype="varchar" precision="80" phptype="string" null="false" default="" />
                      <field key="description" dbtype="varchar" precision="255" phptype="string" null="false" default="" />
                      <field key="editor_type" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
                      <field key="category" dbtype="int" precision="11" phptype="integer" null="false" default="0" index="fk" />
                      <field key="locked" dbtype="tinyint" precision="1" attributes="unsigned" phptype="boolean" null="false" default="0" index="index" />
                      <field key="elements" dbtype="text" phptype="string" />
                      <field key="rank" dbtype="int" precision="11" phptype="integer" null="false" default="0" index="index" />
                      <field key="display" dbtype="varchar" precision="20" phptype="string" null="false" default="" />
                      <field key="display_params" dbtype="text" phptype="string" />
                      <field key="default_text" dbtype="text" phptype="string" />
                      <field key="properties" dbtype="text" phptype="array" null="true" />
                      
                      <aggregate alias="Category" class="modCategory" local="category" foreign="id" cardinality="one" owner="foreign" />
                      <composite alias="TemplateVarTemplates" class="modTemplateVarTemplate" local="id" foreign="tmplvarid" cardinality="many" owner="local" />
                      <composite alias="TemplateVarResources" class="modTemplateVarResource" local="id" foreign="tmplvarid" cardinality="many" owner="local" />
                      <composite alias="TemplateVarResourceGroups" class="modTemplateVarResourceGroup" local="id" foreign="tmplvarid" cardinality="many" owner="local" />
                  </object>


              I hope i helped you in the right direction laugh
                Follow me on twitter: @b03tz
                Follow SCHERP Ontwikkeling on twitter: @scherpontwikkel
                CodeMaster
                • 5340
                • 1,624 Posts
                Found the solution in the forums

                <?php
                $parentId = $modx->resource->get(’parent’);

                $tv = $modx->getObject(’modTemplateVar’, array(’name’ =>’ArticlesBanner’));
                $value = $tv->getValue($parentId);

                print_r($value);
                ?>