Skip to main content

This site requires you to update your browser. Your browsing experience maybe affected by not having the most up to date version.

We've moved the forum!

Please use forum.silverstripe.org for any new questions (announcement).
The forum archive will stick around, but will be read only.

You can also use our Slack channel or StackOverflow to ask for help.
Check out our community overview for more options to contribute.

General Questions /

General questions about getting started with SilverStripe that don't fit in any of the categories above.

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

Routing Problems


Go to End


774 Views

Avatar
Dobby

Community Member, 15 Posts

11 August 2016 at 12:42pm

Routing with Director in the config.php was pretty easy and I had never problems with that.
Now with SS 3.4 makes it harder for me and the documentation doesn't help.

The Routing leads to the right controller. But I can't get the template. I tried several filenames for the ss-file and nothing worked. I also tried to change extension of Page_Controller and Controller. Maybe someone can help me, because I'm a little frustrated why that got so complicated. At least for me.

Let's start with the routes.yml

---
Name: rootroutes
Before: '*'
After: 'framework/routes#rootroutes'
---
Director:
  rules:
    'videoclips/delete': 'VideoclipSeite_Controller'
    'videoclips/$Datum/$Spiel_URL/$OtherID': 'VideoclipSeite_Controller'
    'videoclips': 'VideoclipSeite_Controller'

Here is the code for the controller

class VideoclipSeite_Controller extends Page_Controller {
		
		
	private static $allowed_actions = array (
	'index',
	'delete',
	'Aktuell',
	);
	public function index(SS_HTTPRequest $request) {
	return array();
	}	
    private static $url_handlers = array(
 	'videoclips//$Datum/$Spiel_URL/$OtherID' => 'Aktuell',
 	'videoclips/delete/$ID' => 'delete',
 	'videoclips' => "index"
    );
	
	public function init() {
		parent::init(); 
		}
	
	public function SpielID() {
		if ($this->request->param("Datum") AND $this->request->param("Spiel_URL")){
		$Spiele= Spiele::get()->filter(array('Datum'=>$this->request->param("Datum"), 'Spiel_URL' =>$this->request->param("Spiel_URL")));

		foreach ($Spiele as $Spiel) {
			
		}
		return $Spiel->ID;}	
		
	}
	
	public function Datum() {
		return $this->request->param("Datum");
		}
	public function Spiel_URL() {
		return $this->request->param("Spiel_URL");
		}

	function jahre(){

	 $list = ArrayList::create();
        
        $query = new SQLQuery(array ());
        $query->selectField("DATE_FORMAT(Datum,'%Y') as Jahr")
              ->setFrom("Spiele")
              ->setOrderBy("Datum", "DESC")
              ->setDistinct(true);

        $result = $query->execute();
	 while($record = $result->nextRecord()) {
                
                $list->push(ArrayData::create(array(
                    'Jahr' => $record['Jahr'],
                    'Spiele' => Spiele::get()->filter(array("Datum:StartsWith" => $record['Jahr']))->sort("Datum DESC")
                )));
            }
	return $list;
	}		
		
	public function Spiele()
	{
		$Spiele= Spiele::get()->filter(array('Public'=>0))->sort('Datum');
		$Spiele->URLSegment=$this->URLSegment;
		return $Spiele;
	}
	
	public function Aktuell()
	{
		
		$Spiele= Spiele::get()->filter(array('ID'=>$this->SpielID()))->sort('Datum');
		return $Spiele;
	}

	public function Dikussionen()
	{
		
		$Spiele= Video_Diskussion::get()->filter(array('ClipID'=>$this->request->param("OtherID")))->sort('Created');
		return $Spiele;
	}

	
	public function Zahl()
	{
		
		Return Videoclips::get()->filter(array('SpielID' => $this->SpielID()))->Count();
	}
	
		function delete() {
		
		// ID aus der URL auslesen
		$id=$this->SpielID();
		// DataObject anhand der ID suchen
		if ($dataToDelete = DataObject::get_by_id("Video_Diskussion", $this->request->param("ID")))
		// gefundenes DataObject löschen und zurück
			{
				$dataToDelete->delete();
				}
	
			$this->redirectBack();
		}	
		
		
	
	public function Clip() {
		$Datum=date('Y-m-d H:i:s');
		if ($this->request->param("OtherID")) {
		$ClipID=$this->request->param("OtherID");}
		else {
			$ClipID=1;
		}
		if ($this->request->param("Datum") AND $this->request->param("Spiel_URL")){
		$Clip = Videoclips::get()->filter(array('SpielID' => $this->SpielID(), 'SortOrder' => $ClipID));
		$Clips = DB::query('SELECT Count(ID) FROM "Video_Diskussion" WHERE ClipID = '.$this->ClipID().' AND SpielID = '.$this->SpielID().'')->value();
		//Video_Diskussion::get()->filter(array('SpielID' => $this->SpielID(), 'ClipID'=>$ClipID));
		}
		if ($Clips >0){	
		$Last=DB::query('SELECT ID FROM `Video_Diskussion` WHERE ClipID = '.$this->ClipID().' ORDER BY ID DESC LIMIT 1')->value();   

              return $Clip;
		
	}	
	
	public function ClipID() {
		if ($this->request->param("OtherID")) {
		$ClipID=$this->request->param("OtherID");}
		else {
			$ClipID=1;
		}	
		$Clips = Videoclips::get()->filter(array('SpielID' => $this->SpielID(), 'SortOrder' => $ClipID));
		foreach ($Clips as $Clip) {
			
		}
		return $Clip->ID;
	}