ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Call module methods from a template

October 12, 2012 8:25am

Subscribe [2]
  • #1 / Oct 12, 2012 8:25am

    garda

    35 posts

    I need to call a function inside the ip to nation module; i’d like to parse the client’s ip instead of the poster’s ip. How would I call a function inside the module from a template (in php)?
    Is it all protected or is there a way to do something like $this->EE->ip_to_nation->...
    Thanks,

    Vincent

  • #2 / Oct 15, 2012 12:51pm

    Dan Decker

    7338 posts

    Hi Vincent,

    Thanks for posting your question to the forums!

    You can use the standard global variable {ip_address} to get the address of the currently logged in user. Visitors to your site are loggeed as Guests, and this works for them too.

    Is that the information you are looking for?

    Cheers,

     

  • #3 / Oct 15, 2012 2:59pm

    garda

    35 posts

    Hi Dan, I tried the following code:

    {exp:ip_to_nation:world_flags type="text"}
            {ip_address}
    {/exp:ip_to_nation:world_flags}

    but it won’t return anything, unless it’s embedded inside channel entries tag like:

    {exp:channel:entries channel="test"}
            {exp:ip_to_nation:world_flags image_url="http://example.com/images/world_flags/"}
                    {ip_address}
            {/exp:ip_to_nation:world_flags}
    {/exp:channel:entries}

    In which case it’s going to return the country of the IP of the user who posted the channel entry..
    I’m using EE2.5.2

  • #4 / Oct 16, 2012 12:16pm

    Robin Sowell

    13255 posts

    You don’t need to put the ip_address tag inside anything.  It’s a global, so you should be able to display it pretty much anywhere.  If you want to put it inside a tag that might have a variable it conflicts with (such as the channel tag), you can use the alternate syntax: logged_in_ip_address.

    Make sense?  Don’t worry about the ip-2-nation module.  Just put the tag where you want to display the user’s IP and it should work.

  • #5 / Oct 24, 2012 7:44am

    garda

    35 posts

    Hi Robin, If I put {ip_address} outside a tag pair, it’ll display the user’s IP. but i need to get the country associated with this ip, so i put it inside the world_flags tag, with type=“text”, but there is no output at all..

    Vincent

  • #6 / Oct 25, 2012 11:01am

    Dan Decker

    7338 posts

    Hi Vincent,

    Can you check the note here? Have you updated your IP 2 Nation database since updating/installing 2.5.2? Installing the Module is only the first step. You need to trigger the database update operation as well.

    Check that for me and let me know your result!

    Cheers,

  • #7 / Oct 25, 2012 11:45am

    Dan Decker

    7338 posts

    Hey Vincent,

    Just to be thorough, I kept poking this and turned up a bug 😕 I filed the report that explains why this isn’t working properly.

    Cheers,

  • #8 / Oct 30, 2012 11:30am

    garda

    35 posts

    Hi Dan, thanks, for now I just modified the source code to take the IP address as a parameter inside the world_flags tag pair.
    Maybe an easier workaround would be to use $_SERVER[‘REMOTE_ADDR’] directly instead of {ip_address}.

    Thanks!

    Vincent

  • #9 / Oct 31, 2012 12:05pm

    Shane Eckert

    7174 posts

    Hey garda,

    Awesome! Glad to hear it.

    Is there anything else we can help you with?

    Cheers,

  • #10 / Oct 31, 2012 12:40pm

    garda

    35 posts

    Hi Shane, no that’s it, thanks!

  • #11 / Nov 01, 2012 11:51am

    Shane Eckert

    7174 posts

    Hey garda,

    Awesome!

    If you need anything else, please just let me know by opening a new thread.

    Cheers,

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases