Results 1 to 12 of 12

Thread: Using $_GET variable

  1. #1
    User
    Join Date
    07-26-09.
    Posts
    175

    Default Using $_GET variable

    Hi guys,
    while trying to develop a module I got stuck on a retrieving $_GET variable. I think following part of code
    Code:
    public function generate()
    {
    ...
    if (!$this->Input->get('id'))
    	{
    		return 'blabla';
    	}
    ...
    }
    ruins other actions. When I run mymodule.html?id=1 browser says that the document was not found (notice that it is NOT "Page not found" generated by TYPOlight). What is strange - mymodule.html?id=0 doesn't occur any error, displays "blabla" and rest of code isn't executed.

    When I remove the code above, mymodule.html not found.

    Why is that? Do I miss something?

  2. #2
    User fbliss's Avatar
    Join Date
    06-19-09.
    Location
    Greenfield, MA
    Posts
    50

    Default Re: Using $_GET variable

    Hi Tru,

    Could you post more code for us? It is hard to tell what is going on without having some context in terms of the entire class file, for example.

  3. #3
    Experienced user
    Join Date
    06-20-09.
    Posts
    1,311

    Default Re: Using $_GET variable

    Maybe this?

    Code:
    $theid = $this->Input->get('id');
    
    if (!(isset($theid))) 
    { 
     return 'blabla';
    }

  4. #4
    User
    Join Date
    06-19-09.
    Posts
    328

    Default Re: Using $_GET variable

    Quote Originally Posted by ramjet
    Maybe this?

    Code:
    $theid = $this->Input->get('id');
    
    if (!(isset($theid))) 
    { 
     return 'blabla';
    }
    this won't work because if you set $theid the "isset" statement will be always true ... take a look at the empty function (http://www.php.net/empty)

    e.g.:
    Code:
    $theid = $this->Input->get('id');
    
    if (empty($theid)) {
      // "no id" action
    }
    Consulenza Contao CMS https://www.intco.it

  5. #5
    User
    Join Date
    07-26-09.
    Posts
    175

    Default Re: Using $_GET variable

    Okay here's the whole code - http://pastie.org/576416
    Content was actually copy-pasted from RssReader and modified to display only one item. It should work following way:
    RssReader displays all titles of rss entries. Each entry forwards to an internal page where is displayed title and description. When you go to the mymodule.html?id=3 you should see rss entry no. 3.

    As you can see I have used empty function (line 43), but it has changed nothing. When I try to access my module page I get HTTP 500 Internal server error.

    I don't really understand that if I cut out the "if" statement from line 43 error still occurs.

  6. #6
    User
    Join Date
    06-19-09.
    Posts
    328

    Default Re: Using $_GET variable

    an http 500 internal server error means that there's something wrong unrelated to php code.

    can you post a link to your live website?

    p.s.

    try to replace the line 43 with
    Code:
    $myId = $this->Input->get('id');
    if (empty($myId)) {
        return 'xxxx';
    }
    maybe you can try to change "id" with something different e.g. "myCustomId" just to test that there's nothing that uses the "id" var
    Consulenza Contao CMS https://www.intco.it

  7. #7
    User
    Join Date
    07-26-09.
    Posts
    175

    Default Re: Using $_GET variable

    Hmm still doesn't work.

    Actually I have this website on my localhost, but will upload for you as soon as possible.

  8. #8
    Core developer
    Official Contao Team
    leo's Avatar
    Join Date
    06-04-09.
    Location
    Wuppertal, Germany
    Posts
    201

    Default Re: Using $_GET variable

    You cannot use a GET variable named "id", because the name is used by TYPOlight to determine the page ID.

    Code:
    mymodule.html?id=1
    is internally rewritten to

    Code:
    index.php?id=mymodule&id=1
    Try to rename your variable.

  9. #9
    User
    Join Date
    07-26-09.
    Posts
    175

    Default Re: Using $_GET variable

    Okay, I have moved website to remote server and now there is no strange behavior.
    At the moment it displays php fatal error which actually makes me happy, because I know module is "working"

  10. #10
    User
    Join Date
    07-26-09.
    Posts
    175

    Default Re: Using $_GET variable

    Okay I made it works! Big thanks to all of you guys for help

    One more question:
    If I place a new file /system/modules/rss_reader/ModuleRssItemReader.php will TYPOlight overwrite/remove it after LiveUpdate/normal update?

  11. #11
    Core developer
    Official Contao Team
    leo's Avatar
    Join Date
    06-04-09.
    Location
    Wuppertal, Germany
    Posts
    201

    Default Re: Using $_GET variable

    No, the Live Update will not touch your custom files.

  12. #12
    User
    Join Date
    07-26-09.
    Posts
    175

    Default Re: Using $_GET variable

    Thank you for your quick reply!

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •