Fatal error: Cannot instantiate non-existent class:updatescontroller on line 97 - php

<?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.

Related

array_key_exists() expects parameter 2 to be array, null given in wp theme

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?

How to pass multiple objects to a template?

I am trying to understand the MVC method with the use of OOP. However it seems like I've hit the wall here.
I am trying to pass multiple objects to the view. But all I can do so far is pass just one object. The ideal result would be passing multiple objects, while keeping the names that are assigned to them in the controller.
The render, start and end functions in the View class go something like this:
public function render($viewName, $data){
$viewAry = explode('/', $viewName);
$viewString = implode(DS, $viewAry);
if(file_exists(ROOT . DS . 'app' . DS . 'views' . DS . $viewString . '.php')){
include(ROOT . DS . 'app' . DS . 'views' . DS . $viewString . '.php');
include(ROOT . DS . 'app' . DS . 'views' . DS . 'layouts' . DS . $this->_layout . '.php');
}else{
die('The view \"' . $viewName . '\" does not exist.');
}
}
public function content($type){
if($type == 'head'){
return $this->_head;
}elseif ($type == 'body'){
return $this->_body;
}
return false;
}
public function start($type){
$this->_outputBuffer = $type;
ob_start();
}
public function end(){
if($this->_outputBuffer == 'head'){
$this->_head = ob_get_clean();
}elseif($this->_outputBuffer == 'body'){
$this->_body = ob_get_clean();
}else{
die('You must first run the start method.');
}
}
And this is how would the controller look like:
public function indexAction(){
$items = $this->PortalModel->getItems();
$collections = $this->PortalModel->getCollections();
$this->view->render('home/index', $items);
}
So this is how I get the one $data object to the view and loop trough it.
But how could I store multiple results from the database to the view?
You should pass an array of variables into view instead of one variable.
public function indexAction(){
$variables = [
'items' => $this->PortalModel->getItems(),
'collections' => $this->PortalModel->getCollections()
];
$this->view->render('home/index', $variables);
}

Class Names are Returned but get_class_methods returns Null using spl_autoload_register

I am trying to read some class files stored in a folder and get their methods.
However, the get_class_methods is returning null. But if I put my server_defines file and index.php into the v1 folder, everything works as it should.
I'm unsure what is going on, since it appears to me (a novice) that everything is included.
Here is the folder structure
Api
server_defines.php
Test
index.php
v1
MyMasterClass.php
Operations
OneClass.php
TwoClass.php
ThreeClass.php
server_defines.php
error_reporting(E_ALL ^ E_STRICT ^ E_DEPRECATED);
ini_set('display_errors', 1);
ini_set('log_errors', 1);
ini_set('error_log', dirname(__FILE__) . '/error_log.txt');
if (!defined("SERVER_DOCUMENT_ROOT")) {
define("SERVER_DOCUMENT_ROOT", $_SERVER['DOCUMENT_ROOT'] . "/");
}
define( "SERVER_API_PATH", SERVER_DOCUMENT_ROOT . "v1/" );
define( "SERVER_API_OPERATIONS_PATH", SERVER_API_PATH . "Operations/" );
Test/index.php
require_once( $_SERVER[ 'DOCUMENT_ROOT' ] . "/server_defines.php" );
spl_autoload_register( function ( $class ) {
$sFile = SERVER_API_PATH . str_replace( '\\', '/', $class ) . '.php';
if (file_exists( $sFile )) {
echo "requiring file: " . $sFile . "<br/>";
require $sFile;
}
} );
var_dump(MyMasterClass::getClassesAndMethods());
* Which Outputs*
requiring file: /Users/myname/Documents/GitHub/myproject/Api/v1/MyMasterClass.php
folder_contents: array(3) {
[0]=>
string(80) "/Users/myname/Documents/GitHub/myproject/Api/v1/Operations/OneClass.php"
[1]=>
string(75) "/Users/myname/Documents/GitHub/myproject/Api/v1/Operations/TwoClass.php"
[2]=>
string(75) "/Users/myname/Documents/GitHub/myproject/Api/v1/Operations/ThreeClass.php"
}
basename: OneClass
get_class_methods: NULL
basename: TwoClass
get_class_methods: NULL
basename: ThreeClass
get_class_methods: NULL
MyMasterClass.php
class MyMasterClass {
public function __toString () {
return $this->result;
}
public function __construct ( ) {
}
public static function getClassesAndMethods () {
$api = new API();
return $api->buildClassesAndMethods();
}
private function buildClassesAndMethods () {
$folder_contents = glob( SERVER_API_OPERATIONS_PATH . '*.{php}', GLOB_BRACE );
echo "<br/>folder_contents: ";
var_dump( $folder_contents );
echo "<br/>";
$collection = array();
foreach ($folder_contents as $name) {
$name = basename( $name, ".php" );
echo "<br/>basename: " . $name . "<br/>";
echo "<br/>get_class_methods: ";
var_dump( get_class_methods( $name ) );
echo "<br/>";
}
return $collection;
}
}
When you move your classes to subfolder, you autoloader isn't able to load those classes since it covers only files located in SERVER_API_PATH. Try to update your autoload method or load classes manually using require_once.
Try
...
foreach ($folder_contents as $name) {
require_once($name);
$name = basename( $name, ".php" );
echo "<br/>basename: " . $name . "<br/>";
echo "<br/>get_class_methods: ";
var_dump( get_class_methods( $name ) );
echo "<br/>";
}
...

opencart 2.3 Default Language Other Than English

I have a website which already works on 2 languages ,russian and english(everything runs well in both languages), now i have added armenian language.
The Problem --- when i switch on the website into armenain language , i see ,for example,in breadcrumbs
text_home button_continue button_login ....
i have checked \catalog\language\armen\armenian.php file and noticed that values of this varables exist.
By the way ,when i add from armenian.php into ,for example, language/armen/common/header .php this code
$_['text_home'] = 'arm_home';
it works , but thit means that i should add by hand in every single page this general variable...
i would like to have more optimal solution ...
from admin panel i set armenain as default language
Maybe ,i should edit system\library\language.php ???
Here is the structure
<?php
class Language {
private $default = 'en-gb';
private $directory;
private $data = array();
public function __construct($directory = '') {
$this->directory = $directory;
}
public function get($key) {
return (isset($this->data[$key]) ? $this->data[$key] : $key);
}
public function set($key, $value) {
$this->data[$key] = $value;
}
// Please dont use the below function i'm thinking getting rid of it.
public function all() {
return $this->data;
}
// Please dont use the below function i'm thinking getting rid of it.
public function merge(&$data) {
array_merge($this->data, $data);
}
public function load($filename, &$data = array()) {
$_ = array();
$file = DIR_LANGUAGE . 'english/' . $filename . '.php';
// Compatibility code for old extension folders
$old_file = DIR_LANGUAGE . 'english/' . str_replace('extension/', '', $filename) . '.php';
if (is_file($file)) {
require($file);
} elseif (is_file($old_file)) {
require($old_file);
}
$file = DIR_LANGUAGE . $this->default . '/' . $filename . '.php';
// Compatibility code for old extension folders
$old_file = DIR_LANGUAGE . $this->default . '/' . str_replace('extension/', '', $filename) . '.php';
if (is_file($file)) {
require($file);
} elseif (is_file($old_file)) {
require($old_file);
}
$file = DIR_LANGUAGE . $this->directory . '/' . $filename . '.php';
// Compatibility code for old extension folders
$old_file = DIR_LANGUAGE . $this->directory . '/' . str_replace('extension/', '', $filename) . '.php';
if (is_file($file)) {
require($file);
} elseif (is_file($old_file)) {
require($old_file);
}
$this->data = array_merge($this->data, $_);
return $this->data;
}
}
Thank you in advance
I used an old package of armenain language ,which wasn't compatible with oc 2.3,
solution https://crowdin.com/project/opencart-translation-v2/hy-AM#

parse_ini_file data is always 1

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"

Categories