We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

MSM, $PREFS->ini('site_id') and AJAX

Development and Programming

Fred Boyle's avatar
Fred Boyle
73 posts
16 years ago
Fred Boyle's avatar Fred Boyle

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.

       
Robin Sowell's avatar
Robin Sowell
13,160 posts
16 years ago
Robin Sowell's avatar Robin Sowell

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?

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

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.

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

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
       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

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?

       
Fred Boyle's avatar
Fred Boyle
73 posts
16 years ago
Fred Boyle's avatar Fred Boyle

Ryan,

Looking back and trying to remember I think I ended up doing a reverse lookup of the site_id via the entry_id. Can you send me your code and explanation of what’s not working and I can try to help?

       
Ryan M.'s avatar
Ryan M.
1,511 posts
16 years ago
Ryan M.'s avatar Ryan M.

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.

       
VRDL's avatar
VRDL
23 posts
about 16 years ago
VRDL's avatar VRDL

As far as i know you are unable to get cookievariables using AJAX and it is not an EE related thing.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.