TYPO3 : The technical reason is: No template was found. View could not be resolved for action "list" - typo3

I'm new in TYPO3 and I'm creating a plugin. when I try to load my view I have this error :
Sorry, the requested view was not found.
The technical reason is: No template was found. View could not be resolved for action "list"
in class "Vendor\Reservationatelier\Controller\ReservationatelierController".
I have seen similars question in slack, and tried the solutions but without success for me.
I added/activated my template to static templates like the answer of this question :
TYPO3: No template was found. View could not be resolved for action
my template are stored in : Resources/Private/Templates/Reservationatelier/List.html
setup.ts :
plugin.tx_reservationatelier_atelier {
view {
templateRootPaths.0 = EXT:reservationatelier/Resources/Private/Templates/
partialRootPaths.0 = EXT:reservationatelier/Resources/Private/Partials/
layoutRootPaths.0 = EXT:reservationatelier/Resources/Private/Layouts/
}
persistence {
storagePid = 157
#recursive = 1
}
}
I don't see where is my mistake, someone have a solution ?
thanks you
EDIT : Object bowser , controller and structure
there is my controller :
<?php
namespace Vendor\Reservationatelier\Controller;
use Vendor\Reservationatelier\Domain\Repository\AtelierRepository;
use TYPO3\CMS\Extbase\Mvc\Controller\ActionController;
use Psr\Http\Message\ResponseInterface;
class ReservationatelierController extends ActionController
{
private $atelierRepository;
/**
* Injects the product repository
*
* #param AtelierRepository $atelierRepository
*/
public function injectAtelierRepository(AtelierRepository $atelierRepository)
{
$this->atelierRepository = $atelierRepository;
}
public function listAction()
{
$ateliers = $this->atelierRepository->findAll();
$this->view->assign('ateliers', $ateliers);
}
}
structure extension :
Solved : the name used in my setup.ts was wrong

You wrote two contradicting paths:
my template are stored in :
Resources/Private/Templates/Reservationatelier/List.html
and
EXT:reservationatelier/Resources/Private/Templates/
So either you move the template a level up (and delete the subfolder) or you adjust the path in the configuration to this
templateRootPaths.0 = EXT:reservationatelier/Resources/Private/Templates/Reservationatelier/

Related

Typo3 Extension Scheduler Command Controller

here is a problem I encountered in TYPO3 Extension Development.
I've written an TYPO3-extension. It will display in browser the news in the DB. But I'd like to configure a scheduler task to recurrently update the news in the DB to be displayed.
In writing this scheduler task I've used a Command Controller.
namespace Vendor\Extension\Command;
class CheckNewsCommandController extends \TYPO3\CMS\Extbase\Mvc\Controller\CommandController
{
public function simpleCommand()
{
$newsRepository = $this->objectManager->get( \Vendor\Extension\Domain\Repository\NewsRepository::class );
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($newsRepository);
$all_news = $newsRepository->findAll();
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($all_news);
}
}
But the variable $all_news contains nothing, it equals to NULL !!! That means, the findAll() Function of the NewsRepository does NOT work at all !!!
In comparison, I've also used this NewsRepository in a normal Controller Class: Vendor\Extension\Controller\NewsController
namespace Vendor\Extension\Controller;
class NewsController extends \TYPO3\CMS\Extbase\Mvc\Controller\ActionController
{
public function listAction()
{
$newsRepository = $this->objectManager->get( \Etagen\EtSocNewsSt\Domain\Repository\NewsRepository::class );
$all_news = $newsRepository->findAll();
\TYPO3\CMS\Extbase\Utility\DebuggerUtility::var_dump($all_news);
}
And, in the NewsController, the function NewsRepository::findAll() DID really work, and returned all records in the DB.
So, who can tell me, why the Repository function will ONLY work in the class Vendor\Extension\Controller\NewsController, but NOT work in the class Vendor\Extension\Command\CheckNewsCommandController ?
The answer is EASY: You need to define the storagePid for your news records in the CommandController OR change the settings of the NewsRepository to IGNORE the storagePid.
How to set the storagePid for CommandController:
https://worksonmymachine.org/blog/commandcontroller-and-storagepid
How to set the repository to ignore storagePid:
http://typo3.sascha-ende.de/docs/development/database/how-to-ignore-the-page-id-pid-in-repository-database-query/

How to access the ext_conf_template.txt (extension configuration) in typoscript?

There are a few settings in the ext_conf_template.txt in my extension.
I want to check the value of one of these settings, but in typoscript, not in PHP.
In PHP it works like this:
unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['myExt'])
How should I do this in typoscript?
Thanks to the answer of Marcus I was able to get a extension configuration setting into typoscript. First create the extension setting in ext_conf_template.txt:
# cat=Storage; type=string; label=storageFolderPid
storageFolderPid = 1
In ext_local_conf.php add the following lines:
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addTypoScriptConstants(
"plugin.tx_extensionname.settings.storageFolderPid = ".$GLOBALS['TYPO3_CONF_VARS']['EXTENSIONS']['extension']['storageFolderPid']
);
Then you can use this variabele in your typosript, for instance to create a submenu of a storage folder:
lib.submenu = CONTENT
lib.submenu {
table = tx_extension_domain_model_article
select {
pidInList = {$plugin.tx_extensionname.settings.storageFolderPid}
selectFields = tx_extensionname_domain_model_article.*
}
...
}
I did something similar in my code snippet extension (see complete code on Github), where I just added a custom TypoScript condition:
[DanielGoerz\FsCodeSnippet\Configuration\TypoScript\ConditionMatching\AllLanguagesCondition]
// some conditional TS
[global]
The condition implementation is quite simple:
namespace DanielGoerz\FsCodeSnippet\Configuration\TypoScript\ConditionMatching;
use DanielGoerz\FsCodeSnippet\Utility\FsCodeSnippetConfigurationUtility;
use TYPO3\CMS\Core\Configuration\TypoScript\ConditionMatching\AbstractCondition;
class AllLanguagesCondition extends AbstractCondition
{
/**
* Check whether allLanguages is enabled
* #param array $conditionParameters
* #return bool
*/
public function matchCondition(array $conditionParameters)
{
return FsCodeSnippetConfigurationUtility::isAllLanguagesEnabled();
}
}
And the check for the actual TYPO3_CONF_VARS value is done in FsCodeSnippetConfigurationUtility:
namespace DanielGoerz\FsCodeSnippet\Utility;
class FsCodeSnippetConfigurationUtility
{
/**
* #return array
*/
private static function getExtensionConfiguration()
{
return unserialize($GLOBALS['TYPO3_CONF_VARS']['EXT']['extConf']['fs_code_snippet']);
}
/**
* #return bool
*/
public static function isAllLanguagesEnabled()
{
$conf = self::getExtensionConfiguration();
return !empty($conf['enableAllLanguages']);
}
}
Maybe that fits your needs.
Handle the configuration via Extension Manager and call ExtensionManagementUtility::addTypoScriptConstants() in your ext_localconf.php to set a TypoScript constant at runtime.
This way the value can be set at one location and is available both in lowlevel PHP and TypoScript setup.

zend controller can't specify layout

I have this code
class PagamentoController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$model_pagamenti = new Model_Pagamento();
$this->_helper->layout->setLayout('/crudabstract/index.phtml');
$this->view->render('/crudabstract/index.phtml');
}
...
and when i run /pagamento/index
i get this error
An error occurred
Application error
Exception information:
Message: script 'pagamento/index.phtml' not found in path (C:/www/www/abc/application/views\scripts/)
Stack trace:
why won't it work ? it's not supposed to be looking for "pagamento/index.phtml", but for "/crudabstract/index.phtml"
thanks
found out how in my own code
$this->_helper->viewRenderer('crudabstract/'.$this->_request->getActionName(), null, true);
the error message states that there is no view script defined for the index action. when you define a controller, zend framework will automatically look for a corresponding view file which is not being found in your case. so create a corresponding view file in
application/views/script/pagamento/index.phtml
and it should work.

action parameters routing not working in Zend framework routes.ini

I'm trying to set up a route in Zend Framework (version 1.11.11) in a routes.ini file, which would allow be to match the following url:
my.domain.com/shop/add/123
to the ShopController and addAction. However, for some reason the parameter (the number at the end) is not being recognized by my action. The PHP error I'm getting is
Warning: Missing argument 1 for ShopController::addAction(), called in...
I know I could set this up using PHP code in the bootstrap, but I want to understand how to do this type of setup in a .ini file and I'm having a hard time finding any resources that explain this. I should also point out that I'm using modules in my project. What I've come up with using various snippets found here and there online is the following:
application/config/routes.ini:
[routes]
routes.shop.route = "shop/add/:productid/*"
routes.shop.defaults.controller = shop
routes.shop.defaults.action = add
routes.shop.defaults.productid = 0
routes.shop.reqs.productid = \d+
Bootstrap.php:
...
protected function _initRoutes()
{
$config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/routes.ini', 'routes');
$router = Zend_Controller_Front::getInstance()->getRouter();
$router->addConfig( $config, 'routes' );
}
...
ShopController.php
<?php
class ShopController extends Egil_Controllers_BaseController
{
public function indexAction()
{
// action body
}
public function addAction($id)
{
echo "the id: ".$id;
}
}
Any suggestions as to why this is not working? I have a feeling I'm missing something fundamental about routing in Zend through .ini files.
Apparently I'm more rusty in Zend than I thought. A few minutes after posting I realized I'm trying to access the parameter the wrong way in my controller. It should not be a parameter to addAction, instead I should access it through the request object inside the function:
correct addAction in ShopController:
public function addAction()
{
$id = $this->_request->getParam('productid');
echo "the id: ".$id;
}
I also realized I can simplify my route setup quite a bit in this case:
[routes]
routes.shop.route = "shop/:action/:productid"
routes.shop.defaults.controller = shop
routes.shop.defaults.action = index

Probable reasons why autoloading wont work in Zend Framework 1.10.2?

Iam writing an application using Zend Framework 1.10.2.
I created few model classes and a controller to process them.
When Iam executing my application and accessing the admin controller. Iam seeing this error.
Fatal error: Class 'Application_Model_DbTable_Users' not found in C:\xampp\htdocs\bidpopo\application\controllers\AdminController.php on line 16
The error clearly shows its an autoloading error.
Hence I wrote this code in the bootstrap file.
protected function initAutoload()
{
$modeLoader = new Zend_Application_Module_AutoLoader(array
('namespace'=>'','basePath'=>APPLICATION_PATH ));
//echo(APPLICATION_PATH);
return $modeLoader;
}
Still the error remains :( . Can anyone suggest me what Iam missing out here?
This is the location of the Model Users class.
C:\xampp\htdocs\bidpopo\application\models\DbTable\Users.php
This is its code.
class Application_Model_DbTable_Users extends Zend_Db_Table_Abstract
{
//put your code here
protected $_name='users';
public function getUser($id)
{
$id = (int)$id;
$row = $this->fetchrow('id='.$id);
if(!$row)
{throw new Exception("Could not find row id - $id");}
return $row->toArray();
}
public function addUser($userDetailArray)
{
$this->insert($userDetailsArray);
}
public function updateUser($id,$userDetailArray)
{
$this->update($userDetailArray,'id='.(int)$id);
}
public function deleteUser($id)
{
$this->delete('id='. (int)$id);
}
}
This is the Admin Controller's code
class AdminController extends Zend_Controller_Action
{
public function init()
{
/* Initialize action controller here */
}
public function indexAction()
{
$this->view->title= "All Users";
$this->view->headTitle($this->view->title);
$users = new Application_Model_DbTable_Users();
$this->view->users = $users->fetchAll();
}
public function addUserAction()
{
// action body
}
public function editUserAction()
{
// action body
}
public function deleteUserAction()
{
// action body
}
You application classes don't follow the proper naming convention for the namespace you've set. The Zend_Application_Module_AutoLoader is a little different than the normal autoloader in that it doesn't simply change the '_' in the class name with '/'. It looks at the second part of the class name and then checks a folder for the existence of the class based on that.
You need to change the line:
$modeLoader = new Zend_Application_Module_AutoLoader(array(
'namespace'=>'Application',
'basePath'=>APPLICATION_PATH
));
This means it will autoload all module classes prefixed with 'Application_'. When it the second part of the class is 'Model_' it will look in "{$basePath}/models" for the class. The '_' in the rest of the class name will be replaced with '/'. So the file path of the file will be "{$basePath}/models/DbTable/Users.php".
Read more here.