I'm trying to implement a PHP Library for detecting CMS I found on github, but I can't for the life of me figure it out.
I am new to php and composer, but I installed composer in my directory, then updated the json as instructed, but it cannot find the classes, despite them all being in the directory.
running this code
include(__DIR__ . "/vendor/autoload.php");
$domain = "http://google.com";
$cms = new DetectCMS($domain);
if($cms->getResult()) {
echo "Detected CMS: ".$cms->getResult();
} else {
echo "CMS couldn't be detected";
}
gives me this error
PHP Fatal error: Uncaught Error: Class 'DetectCMS' not found in D:\Projects\Scraper\ccc.php:12
Stack trace:
#0 {main}
thrown in D:\Projects\Scraper\ccc.php on line 12
here is my file structure:
would anyone have any idea what I'm doing wrong with this information?
Thanks in advance
I think to include a class using the autoloader,in your class, you must do something about it:
in your composer.json
"autoload": {
"psr-4" :{"DetectCMS": "DetectCMS"}
}
after in your class DetectCMS.php:
<?php
use DetectCMS\DetectCMS;
or
<?php
$loader = require 'vendor/autoload.php';
$loader->add('DetectCMS', __DIR__.'DetectCMS');
Related
in my case I get this error massage
Fatal error: Uncaught Error: Class "RandomClass" not found in /webspace/projectfolder/pages/add_eventuser.php:10 Stack trace: #0 {main} thrown in /webspace/projectfolder/pages/add_eventuser.php on line 10
I use
$_SERVER['DOCUMENT_ROOT']
to get the exact path of the file
In my structure i organized the files like this:
projectfolder/includes/class.php where the pointed class should loaded
projectfolder/pages/initiatorpage.php where i got the Fatal Error
public class DatabaseColums
{
public function loadDatabase($databaseName)
{
$databaseName = "test";
return $databaseName;
}
}
include $_SERVER['DOCUMENT_ROOT'].'includes/RandomClass.php';
$dbinput = new DatabaseColums();
echo $dbinput->loadDatabase();
I made the folder/file restrictions read/write/executeable
Cant explain to myself why I got still this massage.
What Issue is behind that.
Thank you for your attention
the problem was a missing / between $_SERVER['DOCUMENT_ROOT'] and /folder/file.php
--right :$_SERVER['DOCUMENT_ROOT']./ folder/file.php
--wrong: $_SERVER['DOCUMENT_ROOT'].folder/file.php
Thank you #Ajmal Praveen and
#ADyson
So i am working on some code and have come across this error and its starting to bug me a little as i cant find out what is wrong
i have 2 files main.php and that includes functions.php now in the main file i have the following code
<?php
include "functions.php";
$NAME = GET_USER_NAME();
?>
That is all thats in the main file now in the functions file i have the following code
<?php
function GET_USER_NAME() {
return 'bob';
}
function GET_USER_AGE() {
return '5';
}
?>
now when i try and open main in my browser i get the error
Fatal error: Uncaught Error: Call to undefined function GET_USER_NAME() in /var/www/html/main.php:3 Stack trace: #0 {main} thrown in /var/www/html/main.php on line 3
i know the file is being included properly as i can run the function
GET_USER_AGE();
from the main file and it returns 5
The only possible solutions to your problem are :
A typo in the function called in the main, which is not the exact same as in your included file (case sensitivity ?)
The include references a file which is not the one you want (but has one of the 2 desired functions)
And also yes, as #Markus-Zeller says, don't use method names like that, as stated here : https://www.php-fig.org/psr/psr-1/#1-overview
I was trying to compress PDF. I try my best to find out some library that can be free too for some limited purpose. I found out iLovePDF Library.
I try to get it done using composer and without composer too But not find any way to resolve it.
My Code:
<?php
require_once('vendor/autoload.php');
// require_once('vendor/ilovepdf/init.php');
$ilovepdf = new Ilovepdf('project_public_key','secret_key');
$myTask = $ilovepdf->newTask('compress');
$file1 = $myTask->addFile('file1.pdf');
$myTask->execute();
$myTask->download();
?>
Fatal error: Uncaught Error: Class 'Ilovepdf' not found in C:\xampp\htdocs\PHP Doc\E15\index.php:11 Stack trace: #0 {main} thrown in C:\xampp\htdocs\PHP Doc\E15\index.php on line 11
You need to use namespaces:
$ilovepdf = new \Ilovepdf\Ilovepdf('project_public_key','secret_key');
Or:
use \Ilovepdf\Ilovepdf;
$ilovepdf = new Ilovepdf('project_public_key','secret_key');
Thank You.
I resolved it by adding below line at the top of index.php
namespace Ilovepdf;
in api.php i use severall classes, with autoloaders. in include them like this
use \protoware\cms\Account as Account;
use \protoware\cms\Content as Content;
use protoware\cms\Count as Count;
include __DIR__ . '/vendor/autoload.php';
Local this works fine, when i upload it on a server i get this
Europe/Brussels] PHP Fatal error: Uncaught Error: Class 'protoware\cms\Content' not found in /data/vhosts/achielvolckaert.be/wwwroot/api.php:97
Stack trace:
#0 {main}
thrown in /data/vhosts/achielvolckaert.be/wwwroot/api.php on line 97
line 97 is the first line where i open a connection:
$content = new protoware\cms\Content();
$data = $content->get_content('medisch');
I have 0 clue how to fix this, i updated autloader, checked if all files were uploaded...
Try add a \ before class name, like $content = new \protoware\cms\Content(); or just $content = new Content() since you have a use statement.
If this class is a dependency, check if its correctly installed (inside your vendor folder, i.e.). Maybe run composer install?
I'm new to Propel and I need to work with a website that was already setup with Propel (1.6.9).
I got this working on my laptop and generated without any errors. (Yay!)
After generating classes (on the same schema.xml and other related files as earlier on) there seem to be some differences. (spotted in file sizes) When I uploaded these files to the web hosting where the old files were doing a fine job, I ran into an error:
Fatal error: Uncaught exception 'PropelException' with message 'Unknown parser class "PropelArrayParser"' in /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/vendor/propel/propel1/runtime/lib/parser/PropelParser.php:101
Stack trace:
#0 /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/vendor/propel/propel1/runtime/lib/om/BaseObject.php(375): PropelParser::getParser('Array')
#1 /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/vendor/propel/propel1/runtime/lib/om/BaseObject.php(424): BaseObject->exportTo('Array', 'fieldName')
#2 /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/src/controllers/UsersController.php(26): BaseObject->__call('toArray', Array)
#3 /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/src/controllers/UsersController.php(26): User->toArray('fieldName')
#4 /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/framework/framework.php(196): require('/var/www/vhosts...')
#5 /var/www/vhosts/10/154462/web in /var/www/vhosts/10/154462/webspace/httpdocs/DOMAIN/vendor/propel/propel1/runtime/lib/parser/PropelParser.php on line 101
The error is referring to:
$case = new AgencyCosts();
$case->fromArray($_POST, BasePeer::TYPE_FIELDNAME);
$case->save();
So I figured something was wrong with includes. That's why I added the following to my init.php:
set_include_path(dirname(DIR) . '/vendor/propel/propel1/runtime/lib/parser' . PATH_SEPARATOR . get_include_path());
require dirname(DIR) . '/vendor/propel/propel1/runtime/lib/parser/PropelJSONParser.php';
Without any success.
The init.php (where the including is done) is available here.
Any help would be appreciated.
You're getting this exception when Propel cannot find the class definition. From Propel's code:
// PropelParse::getParser
if (!class_exists($class)) {
throw new PropelException(sprintf('Unknown parser class "%s"', $class));
}
Propel generates a classmap file, where the paths of all Propel's classes are written. It seems like you just get the wrong file included or wrong paths in it. Take a look at your configuration file for the classmap key:
$conf['classmap'] = include(dirname(__FILE__) . DIRECTORY_SEPARATOR . 'classmap-<you-project-name>-conf.php');
And then examine the contents of that file. It might happen because you blindly moved the files from your computer to the server.