I found that error when I test my site in xampp. Uncaught Error: Class "Routeur" not found in (my route)
index:
<?php
session_start();
define("RACINE", $_SERVER["DOCUMENT_ROOT"] . "/projetWebII/");
define("RACINEWEB", "http://" . $_SERVER["SERVER_NAME"] . ":" . $_SERVER["SERVER_PORT"] . "/projetWebII/");
function mon_autoloader($classe)
{
$repertoires = array(RACINE . "controleurs/", RACINE . "modeles/", RACINE . "vues/");
foreach($repertoires as $rep)
{
if(file_exists($rep . $classe . ".php"))
{
require_once($rep . $classe . ".php");
return;
}
}
}
spl_autoload_register("mon_autoloader");
Routeur::route();
?>
The file that contains the class is Routeur.php
<?php
class Routeur
{
public static function route()
{
$chaineRequete = $_SERVER["QUERY_STRING"];
$posEperluette = strpos($chaineRequete, "&");
$controleur = substr($chaineRequete, 0, $posEperluette);
if($controleur != "")
{
$classe = "Controleur_" . $controleur;
}
else
{
$classe = "Controleur_Boutique";
}
if(class_exists($classe))
{
$objetControleur = new $classe;
$objetControleur->traite($_REQUEST);
}
else
{
die("Erreur 404! Le controleur n'existe pas.");
}
}
}
?>
any idea about hou to solve it ???? Thanks!!!!
I cant see my file, any sugestion?
Related
I have a Joomla Module it will produce an error code with php 8.0.1 on wampserver on helper.php line 121 "Error Code: Non-static method modSidePanelHelper::getModuleById() cannot be called statically". This is helper.php
<?php
// no direct access
defined('_JEXEC') or die;
require_once JPATH_SITE . '/components/com_content/helpers/route.php';
if (!class_exists('LofPanelGroupBase')) {
require_once(dirname(__FILE__) . '/libs/group_base.php');
}
abstract class modSidePanelHelper {
/**
* get list articles
*/
public static function getList($params) {
if ($params->get('enable_cache')) {
$cache = JFactory::getCache('mod_sidepanel_jt1');
$cache->setCaching(true);
$cache->setLifeTime($params->get('cache_time', 15) * 60);
return $cache->get(array('modSidePanelHelper', 'getGroupObject'), array($params));
} else {
return self::getGroupObject($params);
}
}
/**
* get list articles
*/
public static function getGroupObject($params) {
$group = $params->get('group', 'file');
$file = dirname(__FILE__) .'/libs/groups/'. strtolower($group) . '/' . strtolower($group) . '.php';
if (file_exists($file)) {
require_once($file);
$className = 'SidePanelGroup' . ucfirst($group);
if (class_exists($className)) {
$object = new $className($group);
$object->setCurrentPath(dirname(__FILE__) .'/libs/groups/'. strtolower($group) . '/');
}
}
if ($object) {
return $object->getListByParameters($params);
} else {
return array();
}
}
/**
* load css - javascript file.
*
* #param JParameter $params;
* #param JModule $module
* #return void.
*/
public static function loadMediaFiles($params, $module, $theme='') {
$mainframe = JFactory::getApplication();
// if the verion is equal 1.6.x
JHTML::script('modules/' . $module->module . '/assets/script.js');
if ($theme && $theme != -1) {
$tPath = JPATH_BASE .'/templates/'. $mainframe->getTemplate() .'/html/'. $module->module . '/' . $theme .'/assets/style.css';
if (file_exists($tPath)) {
JHTML::stylesheet('templates/' . $mainframe->getTemplate() . '/html/' . $module->module . '/' . $theme . '/assets/style.css');
} else {
JHTML::stylesheet('modules/' . $module->module . '/tmpl/' . $theme . '/assets/style.css');
}
} else {
JHTML::stylesheet('modules/' . $module->module . '/assets/style.css');
}
}
/**
*
*/
public function renderItem(&$row, $params, $layout='_item') {
$mainframe = JFactory::getApplication();
$theme = $params->get('theme');
$tPath = JPATH_BASE .'/templates/'. $mainframe->getTemplate() .'/html/mod_sidepanel_jt1/'. $theme . '/' . $layout . '.php';
$bPath = JPATH_BASE .'/modules/mod_sidepanel_jt1/tmpl/'. $theme . '/' . $layout . '.php';
if (file_exists($tPath)) {
require($tPath);
} elseif (file_exists($bPath)) {
require($bPath);
}
}
/**
* load theme
*/
public static function getLayoutByTheme($module, $group, $theme= '') {
$mainframe = JFactory::getApplication();
// Build the template and base path for the layout
$tPath = JPATH_BASE .'/templates/'. $mainframe->getTemplate() .'/html/'. $module->module . '/' . $theme .'/default.php';
$bPath = JPATH_BASE .'/modules/'. $module->module .'/tmpl/'. $theme .'/default.php';
// If the template has a layout override use it
if (file_exists($tPath)) {
return $tPath;
} elseif (file_exists($bPath)) {
return $bPath;
}
}
public static function getModulesEnable($params) {
$enableModules = array();
for ($i = 0; $i <= 6; $i++) {
$module = $params->get('file' . $i);
if($module){
if (intval($module->enable) == 1) {
$enableModules[] = self::getModuleById($module->image);
}
}
}
return $enableModules;
}
private function getModuleById($id) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select('module, title');
$query->from('#__modules');
$query->where('published=1 AND client_id=0 AND id=' . $db->quote($id));
$db->setQuery($query);
return $db->loadObject();
}
static function getReturnURL($params, $type) {
$app = JFactory::getApplication();
$router = $app->getRouter();
$url = null;
if ($itemid = $params->get($type)) {
$db = JFactory::getDbo();
$query = $db->getQuery(true);
$query->select($db->quoteName('link'));
$query->from($db->quoteName('#__menu'));
$query->where($db->quoteName('published') . '=1');
$query->where($db->quoteName('id') . '=' . $db->quote($itemid));
$db->setQuery($query);
if ($link = $db->loadResult()) {
if ($router->getMode() == JROUTER_MODE_SEF) {
$url = 'index.php?Itemid=' . $itemid;
} else {
$url = $link . '&Itemid=' . $itemid;
}
}
}
if (!$url) {
// stay on the same page
$uri = clone JFactory::getURI();
$vars = $router->parse($uri);
unset($vars['lang']);
if ($router->getMode() == JROUTER_MODE_SEF) {
if (isset($vars['Itemid'])) {
$itemid = $vars['Itemid'];
$menu = $app->getMenu();
$item = $menu->getItem($itemid);
unset($vars['Itemid']);
if (isset($item) && $vars == $item->query) {
$url = 'index.php?Itemid=' . $itemid;
} else {
$url = 'index.php?' . JURI::buildQuery($vars) . '&Itemid=' . $itemid;
}
} else {
$url = 'index.php?' . JURI::buildQuery($vars);
}
} else {
$url = 'index.php?' . JURI::buildQuery($vars);
}
}
return base64_encode($url);
}
}
line 121 is like this: $enableModules[] = self::getModuleById($module->image);
the self::getModuleById seems deprecated on php 8. Changing that line like this
$enableModules[] = (new modSidePanelHelper)->getModuleById($module->image);
causes another error code like this
Error Code: Cannot instantiate abstract class modSidePanelHelper
any suggestion? Thanks in advance
You have an abstract class:
abstract class modSidePanelHelper {
public static function getList($params) {
// ...
}
public static function getGroupObject($params) {
// ...
}
public static function loadMediaFiles($params, $module, $theme='') {
// ...
}
public function renderItem(&$row, $params, $layout='_item') {
// ...
}
public static function getLayoutByTheme($module, $group, $theme= '') {
// ...
}
public static function getModulesEnable($params) {
// ...
}
private function getModuleById($id) {
// ...
}
static function getReturnURL($params, $type) {
// ...
}
}
The only non-static function is getModuleById, which cannot be called from a static context of this class directly. You either have to create a new concrete class and call its instance then or make this function static.
In this case, I understand that making this class abstract is for preventing calling the constructor of this class, and this functionality is clearly only for static methods execution.
Then, replace:
private function getModuleById($id) {
// ...
}
with:
private static function getModuleById($id) {
// ...
}
I think you also have to do the same for the renderItem function, as long as it's not used here, it has to be executed in a static context if you need to execute it from some other place.
I was updating my client's website and I encountered this error.
I looked in the file where the error was and it's this code:
function asset_path($filename) {
$dist_path = get_template_directory_uri() . '/dist/';
$directory = dirname($filename) . '/';
$file = basename($filename);
static $manifest;
if (empty($manifest)) {
$manifest_path = get_template_directory() . '/dist/' . 'assets.json';
$manifest = new JsonManifest($manifest_path);
}
if (array_key_exists($file, $manifest->get())) {
return $dist_path . $directory . $manifest->get()[$file];
} else {
return $dist_path . $directory . $file;
}
}
especially, this code in question
if (array_key_exists($file, $manifest->get())) {
return $dist_path . $directory . $manifest->get()[$file];
} else {
return $dist_path . $directory . $file;
}
What's wrong with this code above and how do I fix it?
This flash message helper is from traversymvc: a custom open-source php mvc.
My question is: is it necessary to check if ($_SESSION[$name]) is not empty on line 6(3rd if) when we've already made sure that it is not empty from the if condition before it.
Thanks.
<?php
session_start();
function flash($name = '', $message = '', $class = 'alert alert-success') {
if (!empty($name)) {
if (!empty($message) && empty($_SESSION[$name])) {
if (!empty($_SESSION[$name])) {
unset($_SESSION[$name]);
}
if (!empty($_SESSION[$name . '_class'])) {
unset($_SESSION[$name . '_class']);
}
$_SESSION[$name] = $message;
$_SESSION[$name . '_class'] = $class;
} elseif (empty($message) && !empty($_SESSION[$name])) {
$class = !empty($_SESSION[$name . '_class']) ? $_SESSION[$name . '_class'] : '';
echo '<div class= "' . $class . '" id="msg-flash">' . $_SESSION[$name] . '</div>';
unset($_SESSION[$name]);
unset($_SESSION[$name . '_class']);
}
}
}
I try to parse a ini file to load PHP classes from it but whenever parse_ini_file parses the file, the variable that holds the content is always only "1".
Here is my code:
private $plugins = array();
public function __construct() {
Logger::log("Loading plugins");
Logger::debug("Loading " . APP_ROOT . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "plugins.ini");
if (file_exists(APP_ROOT . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "plugins.ini")) {
$data = parse_ini_file(APP_ROOT . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "plugins.ini", true);
foreach ($data as $k => $d) {
if (class_exists($k)) {
$plugin = $this->createPlugin($k);
if ($plugin instanceof Plugin) {
$this->init($plugin, $d);
} else {
Logger::error("Plugin doesn't implements interface Plugin");
}
} else {
Logger::error("Can't load plugin $k");
}
}
} else {
Logger::error(APP_ROOT . DIRECTORY_SEPARATOR . "config" . DIRECTORY_SEPARATOR . "plugins.ini doesn't exists");
}
}
public function createPlugin($name) {
$plugin = unserialize(
sprintf(
'O:%d:"%s":0:{}', strlen($name), $name
)
);
return $plugin;
}
public function init(Plugin $plugin, $data) {
try {
Logger::log("Adding plugin " . get_class($plugin));
Logger::debug("Calling init");
$plugin->init($data);
$this->plugins[get_class($plugin)] = $plugin;
} catch (PluginException $ex) {
Logger::error("Error while init plugin");
}
}
The ini file:
[\eBot\Plugins\Official\MissionChecker]
url=http://someurl
I tried to add a log message after
foreach ($data as $k => $d) {
But this line was never called, therefore $data must be empty, buw how is that possible?
var_dump and print_r($data) show me "1".
I solved the problem by putting the url in the ini file in quotes.
[\eBot\Plugins\Official\MissionChecker]
url="http://someurl"
<?php
/** Check if environment is development and display errors **/
function setReporting() {
if (DEVELOPMENT_ENVIRONMENT == true) {
error_reporting(E_ALL);
ini_set('display_errors','On');
} else {
error_reporting(E_ALL);
ini_set('display_errors','Off');
ini_set('log_errors', 'On');
ini_set('error_log', ROOT.DS.'tmp'.DS.'logs'.DS.'error.log');
}
}
/** Check for Magic Quotes and remove them **/
function stripSlashesDeep($value) {
$value = is_array($value) ? array_map('stripSlashesDeep', $value) : stripslashes($value);
return $value;
}
function removeMagicQuotes() {
if ( get_magic_quotes_gpc() ) {
$_GET = stripSlashesDeep($_GET );
$_POST = stripSlashesDeep($_POST );
$_COOKIE = stripSlashesDeep($_COOKIE);
}
}
/** Check register globals and remove them **/
/*function unregisterGlobals() {
if (ini_get('register_globals')) {
$array = array('_SESSION', '_POST', '_GET', '_COOKIE', '_REQUEST', '_SERVER', '_ENV', '_FILES');
foreach ($array as $value) {
foreach ($GLOBALS[$value] as $key => $var) {
if ($var === $GLOBALS[$key]) {
unset($GLOBALS[$key]);
}
}
}
}
}*/
/** Routing **/
function routeURL($url) {
global $routing;
foreach ( $routing as $pattern => $result ) {
if ( preg_match( $pattern, $url ) ) {
return preg_replace( $pattern, $result, $url );
}
}
return ($url);
}
/** Main Call Function **/
function callHook() {
global $url;
global $default;
global $sent;
$queryString = array();
if (!isset($url)) {
$controller = $default['controller'];
$action = $default['action'];
} else {
$url = routeURL($url);
$urlArray = array();
$urlArray = explode("/",$url);
$controller = $urlArray[0];
array_shift($urlArray);
if (isset($urlArray[0])) {
$action = $urlArray[0];
array_shift($urlArray);
} else {
$action = 'view'; // Default Action
}
$queryString = $urlArray;
if(isset($queryString[0]))
$sent=$queryString[0];
//echo $sent;
}
$controllerName = $controller;
$controller = ucwords($controller);
$model = rtrim($controller, 's');
$controller .= 'Controller';
//echo($model);
//echo($controllerName);
//echo($action);
//echo phpinfo();
**$dispatch = new $controller($model,$controllerName,$action);**
if ((int)method_exists($controller, $action)) {
//call_user_func_array(array($dispatch,"beforeAction"),$queryString);
call_user_func_array(array($dispatch,$action),$queryString);
//call_user_func_array(array($dispatch,"afterAction"),$queryString);
} else {
/* Error Generation Code Here */
}
}
/** Autoload any classes that are required **/
function __autoload($className) {
if (file_exists(ROOT . DS . 'library' . DS . strtolower($className) . '.class.php')) {
include_once(ROOT . DS . 'library' . DS . strtolower($className) . '.class.php');
} else if (file_exists(ROOT . DS . 'application' . DS . 'controller' . DS . strtolower($className) . '.php')) {
include_once(ROOT . DS . 'application' . DS . 'controller' . DS . strtolower($className) . '.php');
} else if (file_exists(ROOT . DS . 'application' . DS . 'model' . DS . strtolower($className) . '.php')) {
include_once(ROOT . DS . 'application' . DS . 'model' . DS . strtolower($className) . '.php');
} else {
/* Error Generation Code Here */
}
}
setReporting();
removeMagicQuotes();
//unregisterGlobals();
callHook();
*****//
When I uploaded this file on server it is showing the error
Fatal error: Cannot instantiate non-existent class:updatescontroller on line 97
pointing to the line
$dispatch =new $controller($model,$controllerName,$action);
Please help me determine what is going wrong.
Also the same server is also not allowing me to run the unregisterGlobals() function and showing “too many errors for undefined index”.
The complete project is running very well on my localhost server.
From the error message I guess you are missing an included file that declares the updatescontroller class. Maybe you need to upload the entire project?
It also seems that your local PHP configuration doesn't match the remote configuration. Try matching your local php.ini with the remote server to make local testing more realistic.
If at all possible try to match the PHP version on your local server with the remote server. There can be subtle differences between versions.