Jump to:

3462 Posts in 1065 Topics by 740 members

Data Model Questions

SilverStripe Forums » Data Model Questions » PassedID can not be checked ?!?

Moderators: martimiz, Sean, biapar, Willr, Ingo, swaiba, simon_w

Page: 1
Go to End
Author Topic: 1034 Views
  • markus85
    Avatar
    Community Member
    12 Posts

    PassedID can not be checked ?!? Link to this post

    Hello folks, that´s my situation:
    I have a page called "SpielerHolder" containing many DataObjects "Spieler". If you click on one of these "Spieler" you click on a link to "DetailSpieler" where some details are shown.

    I created a link and added the $ID of the selected "Spieler"
    In the page "DetailSpieler" I want to get the whole DataObject from the Page_Controller but this doesnt work.
    Here is the code:

    SpielerHolder.ss:

    <td><a href="DetailSpieler/$ID">$Vorname $Nachname</a></td>

    DetailSpieler.ss

    <% control showSpieler %>

          $Vorname $Nachname

       <% end_control %>

    DetailSpieler.php:

    class DetailSpieler_Controller extends Page_Controller{

       function showSpieler(){

          if($id = Director::urlParam('ID')) {      // Wir haben eine ID erhalten
             return DataObject::get_by_id("Spieler", $id);

          }
          else{
             return DataObject::get_by_id("Spieler",1);
          }

       }

    }

    In the if-clause I check whether there is an ID or not, the code in this clause is never been executed.
    I always get the DataObject in the else-clause.

    Here is an example URL:
    "http://localhost/knights/DetailSpieler/5"

    Can anyone give me a hint why the if-clause isn´t executed?

  • markus85
    Avatar
    Community Member
    12 Posts

    Re: PassedID can not be checked ?!? Link to this post

    Here is a working code snippet for the prob. above

    function getAuftrag(){
          $Params = Director::urlParams();
          $auftragsID = $Params['Action'];
          if(is_numeric($auftragsID))
             return DataObject::get_by_id("Auftrag", "$auftragsID");
       }

    1034 Views
Page: 1
Go to Top

Want to know more about the company that brought you SilverStripe? Then check out SilverStripe.com

Comments on this website? Please give feedback.