Trying to get a module to be MSM aware, although parts use AJAX and I’m running into issues in the code having the proper site_id.
What would be the best way to ensure that $PREFS->ini(‘site_id’) is in the proper context?
Currently $PREFS->ini(‘site_id’) always returns the default site_id of 1.
That should do the trick. You might take a look at Fresh variables- it’s ‘aware’ both backend and frontend and uses the site id in some js as well.
Can you layout how you’re using it?
Fred - did you figure this out? I’m having the exact same issue. I can’t seem to use “global $PREFS” inside this Live search function I have (based off original Live Search by Mark Huot) so I cannot get the site id. I’m trying to make the Live Search MSM aware.
I’ll open Fresh Variables right now to see if that helps solve the issue.
Nothing in Fresh Variables I’m not already aware of.
This boils down to the fact that I cannot seem to use $PREFS (or any global) in this LiveSearch function for whatever reason. If I try to do this:
global $PREFS;
$site_id = $PREFS->ini('site_id');
I get this from Firebug:
Fatal error: Call to a member function ini() on a non-object in … on line 1126
I think I got things fixed to the point that Fred had above. I added this to the problematic function:
require_once("../core/core.prefs.php");
$PREF = new Preferences();
// Get the current Site ID
$site_id = $PREF->ini('site_id');
But it looks like the site_id always returns a 1, even when I flip over to site two. Any ideas?
All of my code is based on Mark Huot’s original Live Search code, including most of the AJAX.
I got this to work by passing the site ID in the query string. In my show_full_control_panel_end function, I had this:
$ext_url = '/'.$PREFS->core_ini['system_folder'].'/extensions/'. MD_Ext_Filename .'?ls_get_query=';</code></pre>
Which I changed to this:
<pre><code>// Get the current Site ID
$site_id = $PREFS->ini('site_id');
$ext_url = '/'.$PREFS->core_ini['system_folder'].'/extensions/'. MD_Ext_Filename .'?sid='.$site_id.'&ls;_get_query=';</code></pre>
Then, the problematic <b><span style="color:blue;">LiveSearchResults()</span></b> function that does the AJAX search. It was in that function that I could not set "global $PREFS" and use any of the things that provides.
I'm not sure if any of it has to do with the fact that this Extension has never worked when this line is included:
<pre><code>if ( ! defined('EXT')) { exit('Invalid file request'); }
No results will show unless that is commented out. So in the LiveSearchResults() function we needed to add:
define('EXT', 'tricky');
Not sure that has anything to do with it.
Currently the LiveSearchResults() function is inside the Md_livesearch class, so I thought $PREFS would be available.
Not a huge deal now that I’m just passing the site id in the query string to the SQL query, but if anyone can shed any light, that would be helpful.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.