We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 19328
    • 433 Posts
    I'm using advSearch to search for users. It's working, but somehow I just can't get the placeholders for the joined table with user attributes to show. I can search for them though, so the table is joined correctly in the search.

    This is my queryhook 'searchUsers':
    $main = array(
        'package' => 'modx',
        'packagePath' => '/home/mydomain/domains/mydomain.com/public_html/core/model/modx/',   
        'class' => 'modUser',                          
        'fields' => 'username',                        
        'withFields' => 'username',                    
        'sortby' => 'modUser.username DESC',
        'tablePrefix' => 'modx_'
    );
    
    $joined = array(
        array(
            'package' => 'modx',        
            'packagePath' => '/home/mydomain/domains/mydomain.com/public_html/core/model/modx/', 
    	'class' => 'modUserProfile',
    	'withFields' => 'fullname,city',
            'fields' => 'fullname,city',
            'joinCriteria' => 'modUser.id = modUserProfile.internalKey',
    	'tablePrefix' => 'modx_'
        )
    );
    
    
    $qhDeclaration = array( 
     'qhVersion' => '1.2', // version of queryHook - to manage futures changes 
     'main' => $main, 
     'joined' => $joined,
    ); 
    $hook->setQueryHook($qhDeclaration);
    
    return true;


    And these are the snippet calls:

    [[AdvSearchForm? 
    &searchIndex=`zoekterm` 
    &tpl=`zoekformulier` 
    &asId=`mysearch` 
    &addJs=`0` 
    &addCss=`0` 
    &addJQuery=`0`
    ]]
    
    [[!AdvSearch? 
      &perPage=`10` 
      &queryHook=`searchUsers`
     &debug=`0`
     &tpl=`zoekresultaat`
     &asId=`mysearch`
     &searchIndex=`zoekterm`
    ]]


    And last, this is the 'zoekresultaat' chunk:

    <li>
    [[+username]] - [[+id]]
    <h3>[[+fullname]]</h3>
    <span class="city">[[+city]]</span>
    </li>


    When I do a search, even for a word that is only present in the joined table (like the city), I get the correct amount of search results but the only placeholders that are working are username and id. The 'fullname' and 'city' placeholders are just empty. I tried all sorts of things and still don't know what I'm doing wrong.

    I do get this error in the error log, and I'm wondering if this is related:

    [2014-02-05 11:32:08] (ERROR @ /index.php) Error HY000 executing statement: 
    Array
    (
        [0] => HY000
        [1] => 1267
        [2] => Illegal mix of collations (latin1_swedish_ci,IMPLICIT) and (utf8_general_ci,COERCIBLE) for operation 'like'
    )


    But I would think not because the search IS being done right, it's just the placeholders that are not working.

    Thanks for any help on this!

    This question has been answered by michelle84. See the first response.

    [ed. note: michelle84 last edited this post 10 years, 2 months ago.]
      • 19328
      • 433 Posts
      I still can't get this to work... Must be doing something wrong. Anyone here who can confirm that it is possible to use placeholders for a joined table like this at all?

      The error I was getting yesterday is gone now, so that can't be the problem. Now I get:

      (ERROR @ /index.php) Could not load class: modValidator from validation.modvalidator.
      • discuss.answer
        • 19328
        • 433 Posts
        I found the solution!

        This works: [[+modUserProfile_city]] instead of [[+city]], and [[+modUserProfile_fullname]] instead of [[+fullname]] and so on.