I'm trying to get started with TYPO3 extensions and was following this tutorial to get to see the basics.
In the backend everything works fine, but on the front end I get an error:
Oops, an error occurred! Code: 20170209104827c3b58d58 -
{"exception":"exception 'ReflectionException' with message 'Class
Tx_Inventory_Controller_InventoryController does not exist'
My files are exactly the same as in the tutorial. I have no idea what is causing this. I assume I made some dumb mistake with namespaces, but they seem to be all correct.
The controller class can be found below and is located in typo3conf/ext/inventory/Classes/Controller/
<?php
namespace \MyVendor\Inventory\Controller;
use \TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use \TYPO3\CMS\Core\Utility\GeneralUtility;
use \MyVendor\Inventory\Domain\Model\Repository\ProductRepository;
class InventoryController extends ActionController {
public function listAction() {
$productRepository = GeneralUtility::makeInstance(ProductRepository::class)
$products = $productRepository->findAll();
$this->view->assign('products', $products);
}
}
?>
When developing a new extension in a composer installed TYPO3 V9 (here: 9.4) the autoload part has to be added to the central root composer.json. Found it here (German). Following the steps in the OPs mentioned tutorial leads to a core exception:
Core: Exception handler (WEB): Uncaught TYPO3 Exception: #1278450972:
Class MyVendor\StoreInventory\Controller\StoreInventoryController does not exist.
Reflection failed.
As long as the extension is not installed via composer, e.g because it's newly developed, composer does not find the appropriate composer.json file in the extensions directory. Hence TYPO3 does not find any classes in the new extensions Classes directory. To resolve the issue the autoload configuration has to be added to the root composer.json. Just put the following lines into composer.json within the installations base directory:
{
"repositories": [
{ "type": "composer", "url": "https://composer.typo3.org/" }
],
...
"autoload": {
"psr-4": {
"MyVendor\\StoreInventory\\": "public/typo3conf/ext/store_inventory/Classes/"
}
}
}
Then regenerate the autoload configuration:
composer dumpautoload
You possibly have to clear the cache as well in the backend.
It looks like your class is not autoloaded. If you don't use composer to make your autoload, take a look in your typo3conf/autoload/autoload_classmap.php file.
You should find an entry corresponding to your file. You will see if you have a path error.
Remove backslashes - try with
<?php
namespace MyVendor\Inventory\Controller;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use TYPO3\CMS\Core\Utility\GeneralUtility;
use MyVendor\Inventory\Domain\Model\Repository\ProductRepository;
class InventoryController extends ActionController {
public function listAction() {
$productRepository = GeneralUtility::makeInstance(ProductRepository::class)
$products = $productRepository->findAll();
$this->view->assign('products', $products);
}
}
Ensure you add Vendorname to extension key, when you register your plugin, see ext_tables.php and write 'MyVendor.'.$_EXTKEY instead of $_EXTKEY like
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'MyVendor.'.$_EXTKEY,
'List',
'The Inventory List'
);
I had exactly the same problem - it happens if Typo3 installation is done by composer. To solve this problem see this page of the docs.
Try to add autoload in your ext_emconf.php (replace 'Vendor\\Extensionkey\\') and uninstall and install your extension again (to rebuild PHP autoload information)
'autoload' =>
array (
'psr-4' =>
array (
'Vendor\\Extensionkey\\' => 'Classes',
),
),
'_md5_values_when_last_written' => 'a:0:{}',
'suggests' => array(
),
Related
I have a custom frontend extension that I have installed on TYPO3 10.
I took a snippet of code from another friend extension and I have some problem to declare the hook class:
under hooks I have a file PageLayoutView.php.
class PageLayoutView implements \TYPO3\CMS\Backend\View\PageLayoutViewDrawItemHookInterface {...
Then in the ext_localconf.php I have added this line:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['cms/layout/class.tx_cms_layout.php']['tt_content_drawItem'][$_EXTKEY] = \MyVendor\myTheme\Hooks\PageLayoutView::class;
in ext_tables.php file i have the following namespace:
call_user_func(
function()
{
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
'Myvendor.myExtname',
'Templates',
'Ext name'
);
In the backend I get this error:
(1/1) Error
Class 'MyVendor\myTheme\Hooks\PageLayoutView' not found
what i'm missing here ?
Did you try to dump the autoload information in the TYPO3 Install Tool?
If it's a composer based installation, try to remove the extension completely and require it again afterwards.
And you should check the namespace in PageLayoutView.php.
After following the composer installation guide for v10 of typo3. I pointed apache vhost to the public folder. Once I navigate to the index.php location in the browser, I get this error
Fatal error: Uncaught ArgumentCountError: Too few arguments to function
TYPO3\CMS\Core\Imaging\IconFactory::__construct()
0 passed in /home/user/projects/typo3/public/typo3/sysext/core/Classes/Utility/GeneralUtility.php
on line 3423
and exactly 2 expected in
/home/user/projects/typo3/public/typo3/sysext/core/Classes/Imaging/IconFactory.php:71
It looks like a dependency injection problem. Please can anybody help with this error
For me this issue occured after moving an existing project from a server into DDEV (which is similar to changing the path/URL by a vhost config). My guess is it has to do with changed paths/URLs in cached files. This is how I solved it:
A) Manually delete all cached files:
t3project$ rm -rf public/typo3temp/*
t3project$ rm -rf var/*
B) Also I had to change the ownership of some autogenerated folders/files to my current user (sudo chown -R myuser:myuser t3project/), then I was able to use the "Fix folder structure" tool in "Environment > Directory Status", now everything was working fine again. Not sure if the last step is helpful for you, as it might be only related to my case where certain folder/files had a wrong owner as they was copied.
I had the same problem today and it occured because I was XClass'ing one of the Core Classes and used GeneralUtility::makeInstance(IconFactory::class) in this code.
The fix is to use DI in this class, just as you suggested. Also flush all caches afterwards to rebuild the DI container.
From this:
class CTypeList extends AbstractList
{
public function itemsProcFunc(&$params)
{
$fieldHelper = GeneralUtility::makeInstance(MASK\Mask\Helper\FieldHelper::class);
$storageRepository = GeneralUtility::makeInstance(MASK\Mask\Domain\Repository\StorageRepository::class);
...
To this:
class CTypeList extends AbstractList
{
protected StorageRepository $storageRepository;
protected FieldHelper $fieldHelper;
public function __construct(StorageRepository $storageRepository, FieldHelper $fieldHelper)
{
$this->storageRepository = $storageRepository;
$this->fieldHelper = $fieldHelper;
}
public function itemsProcFunc(&$params)
{
$this->storageRepository->doStuff();
$this->fieldHelper->doStuff();
...
For future reference for others:
This can also happen in own extensions when the Core uses GeneralUtility::makeInstance on your classes. (e.g. in AuthenticationServices).
The trick here is to make these DI services public like so:
(in extension_path/Configuration/Serivces.yaml)
services:
_defaults:
autowire: true
autoconfigure: true
public: false
Vendor\ExtensionName\Service\FrontendOAuthService:
public: true
Here's documentation for it:
https://docs.typo3.org/m/typo3/reference-coreapi/master/en-us/ApiOverview/DependencyInjection/Index.html#knowing-what-to-make-public
I had this error because i used the Services.yaml file in one of my extensions, but did not configure it correct.
More infos about the file itself can be found here
Since the file is responsible for the dependency injection, small mistakes e.g. in namespaces lead to the above mentioned error.
To locate the error you can uninstall extensions with a Services.yaml.
When you have found the file/extension, you have to check if all Namespaces in the Classes Directory are correct.
This means:
All filenames are correct regarding the Class they contains
All Namespaces in the files are correct for path and filename
The Namespace can be found via composer. So the extension have to be installed via composer or must have an entry in the autoload list of composer.json
The current Behavior:
I wanted to add an extra custom type and followed:
https://docs.typo3.org/p/georgringer/news/master/en-us/DeveloperManual/ExtendNews/AddCustomType/Index.html
Exactly at it was explained there...
The expected behavior/output:
This gives me in the Backend an extra custom type myCustomNewsType.
However, when I call the Frontend, I get:
Core: Exception handler (WEB): Uncaught TYPO3 Exception:
#1476045117: Could not find class definition for name "Galileocr\CustomPackage\Domain\Model\MyCustomNewsType".
This could be caused by a mis-spelling of the class name in the class definition. | TYPO3\CMS\Extbase\Persistence\Generic\Exception\InvalidClassException thrown in file /usr/home/galileo98/public_html/typo3_src-9.5.11/typo3/sysext/extbase/Classes/Persistence/Generic/Mapper/DataMapFactory.php in line 131.
Environment
TYPO3 version(s): [9.5.0]
news version: [e.g. 7.0.5]
Composer (Composer Mode): [ no]
OS: [e.g. OSX 10.13.4]
I have no idea why this occurs, is this example not complete?
Did you configure the class autoloading after adding the new class? If this is a try-out, you should add an autoloading line to the composer.json in the root of your project.
{
"autoload": {
"psr-4": {
"Galileocr\\CustomPackage\\": "typo3conf/ext/custom_package/Classes/"
}
}
}
After that you should regenerate the autoload files by issuing a composer dumpautoload from the directory in which you just edited the composer.json.
I did not make the TYPO3 install with composer (no composer file in the root of my project), did it the "classical" way.
However, you definitely pointed me in the right direction: I opened the file typo3conf/autoload/autoload_psr4.php:
<?php
// autoload_classmap.php #generated by TYPO3
$typo3InstallDir = \TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/';
return array(
'BK2K\\BootstrapPackage\\' => array($typo3InstallDir . 'typo3conf/ext/bootstrap_package/Classes'),
'GeorgRinger\\News\\' => array($typo3InstallDir . 'typo3conf/ext/news/Classes'),
);
So no reference to my custom class...
Therefore, I went to Admin tools->Maintenance->Rebuild PHP Autoload Information and refreshed the autoload info. After that, the same file looks like this:
<?php
// autoload_classmap.php #generated by TYPO3
$typo3InstallDir = \TYPO3\CMS\Core\Core\Environment::getPublicPath() . '/';
return array(
'BK2K\\BootstrapPackage\\' => array($typo3InstallDir . 'typo3conf/ext/bootstrap_package/Classes'),
'Galileocr\\BciePackage\\' => array($typo3InstallDir . 'typo3conf/ext/bcie_package/Classes'),
'GeorgRinger\\News\\' => array($typo3InstallDir . 'typo3conf/ext/news/Classes'),
);
The the problem was fixed!!!
Thanks and regards!
Bert
I have built my first Laravel 4 package.
I have used artisan to create the structure.
I need to use the package to process a queue (as the worker).
I am using the builtin Beanstalk queue and have it configured and I am able to add to the queue.
What is the correct syntax to add the correct path to the class that I would like to use to process the queue.
I can get this working if the class is saved here /app/controllers/TestClass.php ( beacuse this gets autoloaded)
Example:
Route::get('/addtoqueue', function()
{
$message = "This is a test message";
Queue::push('TestClass', array('message' => $message));
return 'Added to Queue';
});
But what should I put in as the class in the queue if the class is in a package?
This file is in workbench:
workbench\vendor\package\src\Vendor\Package
My package composer file contains
"autoload": {
"psr-0": {
"Qwickli\\Tika": "src/"
}
},
Eg.
Queue::push('vendor\package\TestClass', array('message' => $message));
When I run php artisan queue:listen it correctly picks up the items in the queue and but it does NOT find the class (in the package) that I would like to use process the queue.
For some reason the class is not being loaded (or autoloaded) and I don't know how to make that happen.
Thanks for all and any help
Looks like your package classes are not been autoloaded.
Try to access your package folder, workbench/vendor/package and run a compsoer update. If your composer "autoload" settings are correct, this should work.
I have a problem for including Zend Framework in Symfony 2 IN PRODUCTION, because when i use it on local there is no problem ...
I just commited my work on my production server and i have this error :
Fatal error: Class 'Zend_Gdata_AuthSub' not found
And there is this error for any classes of Zend Framework ...
This is my autoload which is good for localhost :
<?php
use Doctrine\Common\Annotations\AnnotationRegistry;
$loader = require __DIR__.'/../vendor/autoload.php';
// intl
if (!function_exists('intl_get_error_code')) {
require_once __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs/functions.php';
$loader->add('', __DIR__.'/../vendor/symfony/symfony/src/Symfony/Component/Locale/Resources/stubs');
$loader->add('Zend_', __DIR__.'/../vendor/zf/library');
}
AnnotationRegistry::registerLoader(array($loader, 'loadClass'));
set_include_path(__DIR__.'/../vendor/zf/library'.PATH_SEPARATOR.get_include_path());
return $loader;
?>
There is probably a problem with the include path but i don't know why ...
Thanks a lot !
If you want to use Composer to pull in the components you need from ZF2 then you could use the information at Zend Framework site Composer info page
As an example you can add code like this to your composer.json file to enable the repository:
"repositories": [
{
"type": "composer",
"url": "https://packages.zendframework.com/"
}
],
"require": {
"zendframework/zend-config": "2.0.*",
"zendframework/zend-http": "2.0.*"
},
You place the names of the packages you want to pull in under the "require" section and the list of available packages is at the link I supplied so you can check the names there.
When you go to install the dependencies you can use this command:
php composer.phar install
Does that help? :-)