.htaccess - Passing a Parameter in to Route PHP -
i have basic route system set , want pass parameter through url use id
button view is:
<p><a href="/card/?idcard=<?= $carded->getid(); ?>" class="btn btn-primary" role="button">view more</a></p> which give me url of : card/?idcard=xy11-25
the controller card page :
use pokemon\pokemon; $id = pokemon::card()->find($_get['idcard']); require 'views/card.view.php'; and route file looks like
$router->define([ '' => 'controllers/index.php', 'about' => 'controllers/about.php', "card" => 'controllers/card.php', 'contact' => 'controllers/contact.php', 'search' => 'controllers/search.php' ]); and lastly .htaccess file is:
options +followsymlinks rewriteengine on rewritecond %{request_filename} !-d rewritecond %{request_filename} !-f rewriterule ^ index.php [l] hopefully makes sense
edit| add router class
class router { protected $routes = []; public static function load($file) { $router = new static; require $file; return $router; } public function define($routes){ $this->routes = $routes; } public function direct($uri){ if (array_key_exists($uri, $this->routes)){ return $this->routes[$uri]; } throw new exception('no route defined uri.'); } } so @ moment router throwing exception, whats best way achieve getting id url.
Comments
Post a Comment