updated routes for get and post
This commit is contained in:
		
							parent
							
								
									937e4581ba
								
							
						
					
					
						commit
						b858af3b55
					
				@ -1,9 +1,9 @@
 | 
				
			|||||||
<?php
 | 
					<?php
 | 
				
			||||||
$routes = [
 | 
					$routes = [
 | 
				
			||||||
    '/about' => [ 
 | 
					    '/about' => [ 
 | 
				
			||||||
        'file' => 'about'
 | 
					        'get' => 'about'
 | 
				
			||||||
    ],
 | 
					    ],
 | 
				
			||||||
    '/' => [ 
 | 
					    '/' => [ 
 | 
				
			||||||
        'file' => 'index'
 | 
					        'get' => 'index'
 | 
				
			||||||
    ]
 | 
					    ]
 | 
				
			||||||
];
 | 
					];
 | 
				
			||||||
@ -12,6 +12,7 @@ class Router {
 | 
				
			|||||||
        $this->routes           = $this->loadRoutes();
 | 
					        $this->routes           = $this->loadRoutes();
 | 
				
			||||||
        $this->path             = $this->preparePath();
 | 
					        $this->path             = $this->preparePath();
 | 
				
			||||||
        $this->query            = $this->prepareQuery();
 | 
					        $this->query            = $this->prepareQuery();
 | 
				
			||||||
 | 
					        $this->request          = $this->getRequestType();
 | 
				
			||||||
        $this->controller       = $this->findController();
 | 
					        $this->controller       = $this->findController();
 | 
				
			||||||
        $this->controllerPath  = $this->setRouteFile();
 | 
					        $this->controllerPath  = $this->setRouteFile();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
@ -47,11 +48,20 @@ class Router {
 | 
				
			|||||||
        return $queryArray;
 | 
					        return $queryArray;
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    private function getRequestType() {
 | 
				
			||||||
 | 
					        // is the requewst a get or post?
 | 
				
			||||||
 | 
					        if (empty($_POST)) {
 | 
				
			||||||
 | 
					            return 'get';
 | 
				
			||||||
 | 
					        } else {
 | 
				
			||||||
 | 
					            return 'post';
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    private function findController() {
 | 
					    private function findController() {
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        // one to one match
 | 
					        // one to one match
 | 
				
			||||||
        if (array_key_exists($this->path, $this->routes)) {
 | 
					        if (array_key_exists($this->path, $this->routes)) {
 | 
				
			||||||
            return $this->routes[$this->path]['file'];
 | 
					            return $this->routes[$this->path][$this->request];
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        foreach ($this->routes as $key => $value) {
 | 
					        foreach ($this->routes as $key => $value) {
 | 
				
			||||||
 | 
				
			|||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user