We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 18373 ☆ A M B ☆
    • 3,141 Posts
    Thanks for sharing your working code, I'm sure people will thank you in the future smiley
      Mark Hamstra • Developer spending his days working on Premium Extras and a MODX Site Dashboard with the ability to remotely upgrade MODX and extras to make the MODX world a little better.

      Tweet me @mark_hamstra, check my infrequent blog at markhamstra.com, my slightly more frequent ramblings at MODX.today or see code at Github.
      • 26503
      • 620 Posts
      Quote from: markh at Apr 12, 2012, 09:28 PM
      Thanks for sharing your working code, I'm sure people will thank you in the future smiley

      No problem ~ I hate it when I come across a half finished thread all problem - then 'thanks guys' & no solution posted :@

      BTW, already have this running through formit & inserting DB records from the form. Just have to clean things up/optimize & figure out the file uploading part out....

      May even github this when done, it's something I find I could be using on at least one out of three sites. [just fiddling with the schema a bt smiley ]

      -sean
        *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

        Sean Kimball CLP, CLS.
        Technical Director / Sr. Developer | BigBlock Studios
        ._______________________________________________.
        Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
        27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
        phone/fax: 905-426-5525
        • 41362
        • 5 Posts
        Hi Sean, I am new to Modx and seem to be getting nowhere,

        I have bought Shawn Wilkerson's book and had no joy, I have used the CMPGenerator and think that I followed the instructions, but when I add [[!my_music]] to my home page all I see is that text so I have came to the forum and came across you project, which is the closest thing to what I wish to do, except all the songs bands etc are my own.

        I have tables songs linked to recordings linked to artists etc, very much like your own structure. How did you manage to get it to work?
          • 26503
          • 620 Posts
          There was quite a bit more to my project so 'what I did' doesn't have a quick answer....

          What is the content of your my_music snippet?
            *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

            Sean Kimball CLP, CLS.
            Technical Director / Sr. Developer | BigBlock Studios
            ._______________________________________________.
            Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
            27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
            phone/fax: 905-426-5525
            • 41362
            • 5 Posts
            Hi Sean, thanks for getting back to me

            Below is my_music schema which was generated using the CPMGenerator, I followed the CMPGenerator.5 minute example

            <?xml version="1.0" encoding="UTF-8"?>
            <model package="my_music" baseClass="xPDOObject" platform="mysql" defaultEngine="MyISAM" version="1.1">
            	<object class="TblArtist" table="tbl_artist" extends="xPDOObject">
            		<field key="artist_id" dbtype="int" precision="10" attributes="unsigned" phptype="integer" null="false" index="pk"  generated="native" />
            		<field key="name" dbtype="varchar" precision="100" phptype="string" null="false" default="" />
            		<field key="bio" dbtype="text" phptype="string" null="false" />
            
            		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
            			<column key="artist_id" length="" collation="A" null="false" />
            		</index>
                            
            	</object>
            	<object class="TblCd" table="tbl_cd" extends="xPDOObject">
            		<field key="cd_id" dbtype="int" precision="10" phptype="integer" null="false" index="pk"  generated="native" />
            		<field key="cd_title" dbtype="varchar" precision="255" phptype="string" null="true" />
            		<field key="cd_info" dbtype="text" phptype="string" null="false" />
            		<field key="cd_image" dbtype="varchar" precision="255" phptype="string" null="true" />
            		<field key="cd_thumbImage" dbtype="varchar" precision="50" phptype="string" null="true" />
            		<field key="cd_images1" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images1txt" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images2" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images2txt" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images3" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images3txt" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images4" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images4txt" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images5" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images5txt" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images6" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images6txt" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images7" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_images7txt" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="cd_artist" dbtype="varchar" precision="50" phptype="string" null="true" default="John Hunter" />
            		<field key="metaKeywords" dbtype="varchar" precision="255" phptype="string" null="true" default="John Hunter, CDs, Music, 404, Songs" />
            		<field key="cd_purchase" dbtype="varchar" precision="20" phptype="string" null="false" default="" />
            
            		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
            			<column key="cd_id" length="" collation="A" null="false" />
            		</index>
                            <composite alias="TblCd" class="TblCd" local="cd_id" foreign="cd_idTitle" cardinality="many" owner="local" />
                            <composite alias="TblCd" class="TblCd" local="cd_id" foreign="cd_idImage" cardinality="many" owner="local" />
            	</object>
            	<object class="TblCdcontent" table="tbl_cdcontent" extends="xPDOObject">
            		<field key="cdTrack_id" dbtype="int" precision="10" phptype="integer" null="false" index="pk"  generated="native" />
            		<field key="cd_idTitle" dbtype="int" precision="10" phptype="integer" null="true" />
            		<field key="cd_idSong" dbtype="int" precision="10" phptype="integer" null="true" />
            		<field key="cd_trackNumber" dbtype="int" precision="10" phptype="integer" null="true" />
            		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
            			<column key="cdTrack_id" length="" collation="A" null="false" />
            		</index>
                            <aggregate alias="TblCdcontent" class="TblCdcontent" local="cd_idSong" foreign="song_id" cardinality="one" owner="foreign" />
                            <aggregate alias="TblCdcontent" class="TblCdcontent" local="cd_idTitle" foreign="cd_title" cardinality="one" owner="foreign" />
              
            	</object>
            
            	<object class="TblRecordings" table="tbl_recordings" extends="xPDOObject">
            		<field key="recording_id" dbtype="int" precision="10" phptype="integer" null="false" index="pk"  generated="native" />
            		<field key="recordingTitle" dbtype="varchar" precision="255" phptype="string" null="true" />
            		<field key="version" dbtype="varchar" precision="255" phptype="string" null="true" />
            		<field key="recording_idSong" dbtype="int" precision="10" phptype="integer" null="true" />
            		<field key="recording_length" dbtype="time" phptype="string" null="true" />
            		<field key="year_recorded" dbtype="year" precision="4" phptype="string" null="true" />
            		<field key="source" dbtype="varchar" precision="255" phptype="string" null="true" />
            		<field key="original" dbtype="varchar" precision="255" phptype="string" null="true" />
            		<field key="notes" dbtype="varchar" precision="255" phptype="string" null="true" />
            		<field key="equipment" dbtype="text" phptype="string" null="true" />
            		<field key="customerRating" dbtype="float" phptype="float" null="false" default="0" />
            		<field key="description" dbtype="text" phptype="string" null="false" />
            		<field key="brief_description" dbtype="text" phptype="string" null="false" />
            		<field key="category_id" dbtype="int" precision="11" phptype="integer" null="true" default="2" />
            		<field key="big_picture" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="picture" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="image_title" dbtype="varchar" precision="255" phptype="string" null="true" />
            		<field key="thumbnail" dbtype="varchar" precision="30" phptype="string" null="true" />
            		<field key="enabled" dbtype="int" precision="11" phptype="integer" null="false" default="0" />
            		<field key="recording_mp3" dbtype="varchar" precision="50" phptype="string" null="true" />
            		<field key="recording_download" dbtype="varchar" precision="50" phptype="string" null="true" />
            		<field key="date_uploaded" dbtype="timestamp" phptype="timestamp" null="false" default="CURRENT_TIMESTAMP" />
            		<field key="artist" dbtype="varchar" precision="20" phptype="string" null="false" default="John Hunter" />
            
            		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
            			<column key="recording_id" length="" collation="A" null="false" />
            		</index>
                            <aggregate alias="TblRecordings" class="TblRecordings" local="recording_id" foreign="recording_idSong" cardinality="one" owner="foreign" />
               
            	</object>
            	<object class="TblSongs" table="tbl_songs" extends="xPDOObject">
            		<field key="song_id" dbtype="int" precision="10" phptype="integer" null="false" index="pk"  generated="native" />
            		<field key="song_title" dbtype="varchar" precision="255" phptype="string" null="true" index="index" />
            		<field key="song_writer" dbtype="varchar" precision="60" phptype="string" null="true" default="Words & Music John Hunter" />
            		<field key="song_year" dbtype="int" precision="10" phptype="integer" null="true" />
            		<field key="song_date" dbtype="date" phptype="date" null="true" index="index" />
            		<field key="song_lyrics" dbtype="text" phptype="string" null="true" />
            		<field key="song_number" dbtype="int" precision="10" phptype="integer" null="true" />
            		<field key="backgroundStory" dbtype="text" phptype="string" null="true" />
            		<field key="songKeywords" dbtype="varchar" precision="255" phptype="string" null="true" />
            
            		<index alias="PRIMARY" name="PRIMARY" primary="true" unique="true" type="BTREE" >
            			<column key="song_id" length="" collation="A" null="false" />
            		</index>
            		<index alias="Date" name="Date" primary="false" unique="false" type="BTREE" >
            			<column key="song_date" length="" collation="A" null="true" />
            		</index>
            		<index alias="Song Title" name="Song Title" primary="false" unique="false" type="BTREE" >
            			<column key="song_title" length="" collation="A" null="true" />
            		</index>
            		<index alias="song_id" name="song_id" primary="false" unique="false" type="BTREE" >
            			<column key="song_id" length="" collation="A" null="false" />
            		</index>
                            <composite alias="TblRecordings" class="TblRecordings" local="song_id" foreign="recording_idSong" cardinality="many" owner="local" />
                            <composite alias="TblRecordings" class="TblRecordings" local="song_id" foreign="cd_idSong" cardinality="many" owner="local" />
             
            	</object>
            </model>


            Below is the script that they stage you create, which has been modified

            <?php
            /**
             * my_music
             */
            $output = '';// this is what the snippet will return
            
            // add package so xpdo can be used:
            $package_path = $modx->getOption('core_path').'components/my_music/model/';
            // see the scheme file and the xml model element and you will see the attribute package and that must match here
            $modx->addPackage('my_music', $package_path);
            
            // lets add some data!
            // see the scheme file and the xml object element and you will see the attribute class and that must match here
            
            // now lets show the data in a quick and dirty table:
            $output .= '
            <table>
                <tr>
                    <th>song_id</th>
                    <th>song_title</th>
                    <th>song_date</th>
                </tr>';
            
            // Note for all HTML you should be using Chunks see: http://rtfm.modx.com/display/revolution20/Chunks#Chunks-ProcessingChunkviatheAPI
            /* build query */
            $query = $modx->newQuery('my_music');
            $rows = $modx->getIterator('my_music, $query);
            
            /* iterate */
            $list = array();
            foreach ($rows as $row) {
                // from object to array you can also do $row->get('song_title');
                $row_array = $row->toArray();
            
                $output .= '
                <tr>
                    <td>'.$row_array['song_id'].'</td>
                    <td>'.$row_array['song_title'].'</td>
                    <td>'.$row_array['song_date'].'</td>
                </tr>';
            }
            $output .= '
            </table>';
            
            return $output;


            And then I [[!my_music]] in the HTML of the home page. All I see is the text [[!my_music]]
              • 26503
              • 620 Posts
              If all you are seeing is "[[!my_music]]" in the page content then I don't think the tag is being processed [well, I know that it's not]

              turn off the visual editor and make sure that the [[ ]] are not being encoded. you did create a snippet called my_music. right?
                *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                Sean Kimball CLP, CLS.
                Technical Director / Sr. Developer | BigBlock Studios
                ._______________________________________________.
                Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                phone/fax: 905-426-5525
                • 41362
                • 5 Posts
                yes the snippet is called my_music and I checked the source code of the home page which I put the[[!my_music]] in and that looks fine too. Very confused
                  • 26503
                  • 620 Posts
                  Quote from: johnrlhunter at Jan 31, 2013, 02:15 PM
                  yes the snippet is called my_music and I checked the source code of the home page which I put the[[!my_music]] in and that looks fine too. Very confused

                  if you PM me the url and credentials I can take a [quick] look, but it still sounds to me like modx is not processing the tag for some reason.
                    *** Not just websites, we also create signage, banners, print, trade show displays and more! ***

                    Sean Kimball CLP, CLS.
                    Technical Director / Sr. Developer | BigBlock Studios
                    ._______________________________________________.
                    Bigblock Studios http://www.bigblockstudios.ca Web site design & development.
                    27-1300 King Street East. Box 167 Oshawa, Ontario L1H8J4 Canada.
                    phone/fax: 905-426-5525
                    • 41362
                    • 5 Posts
                    I would love to, the only problem is I am not working on a live system, but developing it on my laptop with the aim of replacing my music website once all the kinks are worked out. I will see if I can set up a test website and I will send you the details. Many thanks
                    John
                      • 41362
                      • 5 Posts
                      Hi Sean

                      I finally got my test site online on a subdomain of the website I am trying to replicate in Modx. I can't say it has been the easiest thing to do as I had countless permission issues, but it is there. I have sent you over the logon details so that you can get in. You will notice I have had several attempts to get this up and running but the one I am focused on is my_music snippet.

                      I appreciate any help you can give

                      John




                      Quote from: sean69 at Jan 31, 2013, 02:18 PM
                      Quote from: johnrlhunter at Jan 31, 2013, 02:15 PM
                      yes the snippet is called my_music and I checked the source code of the home page which I put the[[!my_music]] in and that looks fine too. Very confused

                      if you PM me the url and credentials I can take a [quick] look, but it still sounds to me like modx is not processing the tag for some reason.