2 years ago
#52158
hardy6413
href link doesnt load css on
Hello I have an issue with my view fieldOverview.php I have a view fields.php which has link to other view
<a href="/fieldOverview/<?= $field->getId(); ?>" class="field-options" >
Past actions and notes
</a>
when user clicks on this link he is correctly redirected but the css doesn't load
however when i will go to http://localhost:8080/fieldOverview
instead of http://localhost:8080/fieldOverview/IDNUMBER
the css styles works properly. Even though both times it goes through this function
public function fieldOverview($id){
//$field = $this->fieldRepository->findFieldById($id);
return $this->render('fieldOverview');
}
my render function
protected function render(string $template = null, array $variables=[]){
$templatePath = 'public/views/'. $template.'.php';
$output = 'File not found';
if (file_exists($templatePath)){
extract($variables);
ob_start();
include $templatePath;
$output = ob_get_clean();
}
print $output;
}
maybe to make it more clear this is my index.php
require 'Routing.php';
$path = trim($_SERVER['REQUEST_URI'], '/');
$path = parse_url($path, PHP_URL_PATH);
Router::get('', 'DefaultController');
Router::get('fields', 'FieldController');
Router::get('fieldOverview', 'FieldController');
Router::run($path);
and my Routing.php
class Router {
public static $routes;
private static $controller;
public static function get($url, $view) {
self::$routes[$url] = $view;
}
public static function post($url, $view) {
self::$routes[$url] = $view;
}
public static function run ($url) {
$urlParts = explode("/", $url);
$action = $urlParts[0];
if (!array_key_exists($action, self::$routes)) {
die("Wrong url!");
}
if(session_status() !== PHP_SESSION_ACTIVE){
session_start();
}
if ((!isset($_COOKIE['user']) || !isset($_SESSION['logged_in_user_account_id'])
|| !isset($_SESSION['logged_in_personal_data_id']))
&& ( $action !== 'signUp' && $action !== 'login')){
self::$controller = self::$routes['login'];
$action = 'login';
}else{
self::$controller = self::$routes[$action];
}
$object = new self::$controller;
$action = $action ?: 'index';
if (isset($urlParts[1])){
$id = intval($urlParts[1]);
}else{
$id ='';
}
$object->$action($id);
}
}
php
html
css
href
0 Answers
Your Answer