Simple Command Controller with TYPO3 - typo3

I want to set up a simple CommandController but I always get a error Message in the backend.
ext_emconf.php
<?php
$EM_CONF[$_EXTKEY] = [
'title' => 'mytask',
'description' => '',
'category' => 'plugin',
'author' => '',
'author_email' => '',
'state' => 'alpha',
'internal' => '',
'uploadfolder' => '0',
'createDirs' => '',
'clearCacheOnLoad' => 0,
'version' => '1.0.0',
'constraints' => [
'depends' => [
'typo3' => '7.6.0-7.6.99',
],
'conflicts' => [],
'suggests' => [],
],
];
ext_localconf.php
<?php
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers']
[$_EXTKEY] = \TYPO3\CMS\mytask\Command\SimpleCommandController::class;
?>
My command class in /Classes/Command/SimpleCommandController.php
<?php
namespace TYPO3\Mytask\Command;
use \TYPO3\CMS\Extbase\Mvc\Controller\CommandController;
class SimpleCommandController extends CommandController {
public function simpleCommand(){
error_log("Hallo");
}
}
?>
I'm able to find the extension in the backend but when I enable it I get a error message and can't use the backend anymore.
Oops, an error occurred!
syntax error, unexpected '$GLOBALS' (T_VARIABLE)
The extension has only these 3 files.

Just try to increase the array without an extension key:
$GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['extbase']['commandControllers'][] = \TYPO3\CMS\mytask\Command\SimpleCommandController::class;

Related

Request timeout - integrate third party library with codeigniter 3

Im working on API integration InPost API Create shippment. I try integrate third party library inpost with codeigniter 3 from GitHub.
https://github.com/imper86/php-inpost-api
I install this library via composer.
View:
<?php echo form_open('inpost_controller/inpost_shippment_post'); ?>
<div class="form-group">
</div>
</div>
<?php echo form_close(); ?><!-- form end -->
Then I call in controller:
require FCPATH . 'vendor/autoload.php';
Full code file Controller:
<?php
defined('BASEPATH') or exit('No direct script access allowed');
require FCPATH . 'vendor/autoload.php';
use Imper86\PhpInpostApi\Enum\ServiceType;
use Imper86\PhpInpostApi\InpostApi;
class Inpost_controller extends Admin_Core_Controller
{
public function __construct()
{
parent::__construct();
}
/**
* Create shippment Inpost Post
*/
public function inpost_shippment_post()
{
$token = 'xxxxx';
$organizationId = 'xxxxx';
$isSandbox = true;
$api = new InpostApi($token, $isSandbox);
$response = $api->organizations()->shipments()->post($organizationId, [
'receiver' => [
'name' => 'Marek Kowalczyk',
'company_name' => 'Company name',
'first_name' => 'Jan',
'last_name' => 'Kowalski',
'email' => 'test#inpost.pl',
'phone' => '888888888',
'address' => [
'street' => 'Malborska',
'building_number' => '130',
'city' => 'Kraków',
'post_code' => '30-624',
'country_code' => 'PL',
],
],
'sender' => [
'name' => 'Marek Kowalczyk',
'company_name' => 'Company name',
'first_name' => 'Jan',
'last_name' => 'Kowalski',
'email' => 'test#inpost.pl',
'phone' => '888888888',
],
'parcels' => [
['template' => 'small'],
],
'insurance' => [
'amount' => 25,
'currency' => 'PLN',
],
'cod' => [
'amount' => 12.50,
'currency' => 'PLN',
],
'custom_attributes' => [
'sending_method' => 'parcel_locker',
'target_point' => 'KRA012',
],
'service' => ServiceType::INPOST_LOCKER_STANDARD,
'reference' => 'Test',
'external_customer_id' => '8877xxx',
]);
$shipmentData = json_decode($response->getBody()->__toString(), true);
while ($shipmentData['status'] !== 'confirmed') {
sleep(1);
$response = $api->shipments()->get($shipmentData['id']);
$shipmentData = json_decode($response->getBody()->__toString(), true);
}
$labelResponse = $api->shipments()->label()->get($shipmentData['id'], [
'format' => 'Pdf',
'type' => 'A6',
]);
file_put_contents('/tmp/inpost_label.pdf', $labelResponse->getBody()->__toString());
}
}
When I post form, after 30 sec I get error 500 Internar Error Server Request timout.
And now im not sure how to debug now. I enable error log in CI3 application/logs/ I open this file but I not see any error related to this.
Could be a defect, or missing http2 setup/cfg.
Since the header in https2 protocol has shorter header on packs.
Not sure doe
https://caniuse.com/http2 < short http2 (TLS, HTTPS) overview
https://factoryhr.medium.com/http-2-the-difference-between-http-1-1-benefits-and-how-to-use-it-38094fa0e95b < http2 as protocol overview in 5 min

fuction() not working in Detailview yii2

When i am going to show user details in Detailview than it throws:
htmlspecialchars() expects parameter 1 to be string, object given
Below is my code for Detailview:
view.php
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'userID',
'userEmail:email',
'userName',
'userMobile',
'userBirthDate',
'userGender',
[
'attribute' => 'interestName',
'format' => 'raw',
'label' => 'Interest',
'value' => $model->getUserinterest(),
],
'userStatus',
'userType',
],
]);
?>
function getUserinterest() {
foreach ($model->userinterest as $userinterest) {
$interestNames[] = $userinterest->interestName;
}
return implode("\n", $interestNames);
}
Since version 2.0.11 value can be defined as closure. Upgrade Yii version to developer version 2.0.11+ and it will work.
Follow the final answer as below:
view.php
<?= DetailView::widget([
'model' => $model,
'attributes' => [
'userID',
'userEmail:email',
'userName',
'userMobile',
'userBirthDate',
'userGender',
[
'attribute' => 'interestName',
'format' => 'raw',
'label' => 'Interest',
'value' => $model->getviewinterest(),
],
'userStatus',
'userType',
],
]);
?>
Users.php(Model)
public function getviewinterest()
{
foreach ($this->userinterest as $userinterest)
{
$interestNames[] = $userinterest->interestName;
}
if(!empty($interestNames)){
return implode("<br/>", $interestNames);
}else{
return "(not set)";
}
}

Expand tx_news TCA

I want to add a field in the backend of the new news module. For that I created a new extension with 3 files in it:
ext_emconf.php
<?php
$EM_CONF[$_EXTKEY] = array(
'title' => 'Expand news',
'description' => 'Expand news',
'category' => 'fe',
'author' => 'SOG',
'author_email' => '-',
'shy' => '',
'dependencies' => '',
'conflicts' => '',
'priority' => '',
'module' => '',
'state' => 'stable',
'internal' => '',
'uploadfolder' => 0,
'createDirs' => '',
'modify_tables' => '',
'clearCacheOnLoad' => 0,
'lockType' => '',
'author_company' => '',
'version' => '0.1.0',
'constraints' => array(
'depends' => array(
),
'conflicts' => array(
),
'suggests' => array(
),
),
'_md5_values_when_last_written' => '',
'suggests' => array(
),
);
?>
ext_tables.php
<?php
/*if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}*/
$tempColumns = array(
'tx_sogexpandnews_test' => array(
'exclude' => 0,
'label' => 'test',
'config' => array(
'type' => 'text',
'cols' => '30',
'rows' => '5',
)
),
);
t3lib_div::loadTCA('tx_news_domain_model_news');
t3lib_extMgm::addTCAcolumns('tx_news_domain_model_news',$tempColumns,1);
t3lib_extMgm::addToAllTCAtypes('tx_news_domain_model_news','tx_sogexpandnews_test', '', 'after:title'));
?>
ext_tables.sql
#
# Table structure for table 'news'
#
CREATE TABLE tx_news_domain_model_news (
tx_sogexpandnews_test text
);
The field is in the database but I dont see the field in the backend when I wanna create a new news item.
I also checked LocalConfiguation.php and made sure that my extension is under the news extension.
Any idea what I miss?
I can't tell why but I deactived news, updated it and installed it again and now I see the field.
cache - cache - cache ... always cache.
If you need to be sure, always delete everything in typo3temp and flush all cf_* tables in your db.
(deactivating and reinstalling almost does the same)

TYPO3 6.0.4 default controller for extension not found

I created my third extension with the extension builder but this one won't install itself properly. I get the error:
The default controller for extension "NtImpressions" and plugin
"Gallery" can not be determined. Please check for
TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin() in your
ext_localconf.php.
I did not modify anything in the extension files. The Plugin is completly generated by the extension builder. This is the ext_localconf.php
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Xxx.' . $_EXTKEY,
'Gallery',
array(
'Galerie' => 'list, show',
),
array(
'Galerie' => '',
)
);
?>
And the ext_tables.php
<?php
if (!defined('TYPO3_MODE')) {
die ('Access denied.');
}
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::registerPlugin(
$_EXTKEY,
'Gallery',
'Galerie'
);
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addStaticFile($_EXTKEY, 'Configuration/TypoScript', 'Impressionen');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::addLLrefForTCAdescr('tx_ntimpressions_domain_model_galerie', 'EXT:nt_impressions/Resources/Private/Language/locallang_csh_tx_ntimpressions_domain_model_galerie.xlf');
\TYPO3\CMS\Core\Utility\ExtensionManagementUtility::allowTableOnStandardPages('tx_ntimpressions_domain_model_galerie');
$TCA['tx_ntimpressions_domain_model_galerie'] = array(
'ctrl' => array(
'title' => 'LLL:EXT:nt_impressions/Resources/Private/Language/locallang_db.xlf:tx_ntimpressions_domain_model_galerie',
'label' => 'bezeichnung',
'tstamp' => 'tstamp',
'crdate' => 'crdate',
'cruser_id' => 'cruser_id',
'dividers2tabs' => TRUE,
'versioningWS' => 2,
'versioning_followPages' => TRUE,
'origUid' => 't3_origuid',
'languageField' => 'sys_language_uid',
'transOrigPointerField' => 'l10n_parent',
'transOrigDiffSourceField' => 'l10n_diffsource',
'delete' => 'deleted',
'enablecolumns' => array(
'disabled' => 'hidden',
'starttime' => 'starttime',
'endtime' => 'endtime',
),
'searchFields' => 'bezeichnung,beschreibung,bilder,bilder_beschreibung,',
'dynamicConfigFile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath($_EXTKEY) . 'Configuration/TCA/Galerie.php',
'iconfile' => \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extRelPath($_EXTKEY) . 'Resources/Public/Icons/tx_ntimpressions_domain_model_galerie.gif'
),
);
?>
I guess the namespace is not set correct and TYPO3 is unable to determine your controller GalerieController->listAction.
The first part of the configurePlugin registers the namespace in TYPO3 6.0, so you need to add this namespace to all classes. The Namespace is parsed to the path where the file with the class can be found. This is the equivalent to the old syntax.
Old syntax:
class Tx_YourExtension_Controller_YourController {
//...
}
is now
<?php
namespace YourVendor\YourExtension\Controller;
class YourController {
//...
}
So following configuration
\TYPO3\CMS\Extbase\Utility\ExtensionUtility::configurePlugin(
'Xxx.' . $_EXTKEY,
...
registers Xxx as Vendor, so all your classes need to be in that namespace
<?php
namespace Xxx\Gallery\Controller
class GalleryController {
// ...
}
Where "Gallary" is you extension key in upper camel case.

How to convert a plugin's config file for use with a newer cakephp version

When looking for a way to provide a cakestrap application with Google Calendar, I came across an older post which mentioned this plugin:
http://www.neilcrookes.com/2009/09/27/get-google-analytics-data-in-your-cakephp/
While trying to add support for Google Calendar it turned out this plugin is not compatible with cakeStrap which I have to use.
I have allready refactored the models, views and controllers but I can't figure out how to convert the gdata-config so it can be used:
<?php
/**
* Coniguration options for Gdata API
*/
class GDATA_CONFIG {
var $analytics = array(
'datasource' => 'gdata',
'driver' => 'analytics',
'email' => '',
'passwd' => '',
'profileId' => '',
'source' => 'CakePHP',
);
var $youtube = array(
'datasource' => 'gdata',
'driver' => 'youtube',
'email' => '',
'passwd' => '',
'source' => 'CakePHP',
);
var $picasa = array(
'datasource' => 'gdata',
'driver' => 'picasa',
'email' => '',
'passwd' => '',
'source' => 'CakePHP',
'cache' => true,
'cacheDuration' => '+1 hours'
);
var $calendar = array(
'datasource' => 'gdata',
'driver' => 'calendar',
'email' => '',
'passwd' => '',
'source' => 'CakePHP',
);
}
?>
This is my first time working with cakePHP so any help is appreciated.
Custom configuration format (using PHP reader) is like:
<?php
$config = array('youtube' =>
'datasource' => 'gdata',
'driver' => 'youtube',
'email' => '',
'passwd' => '',
'source' => 'CakePHP'
));
You can use Configure::load('configuration_file_name.php') to load configuration file and Configuration::read('configuration_array_key') to read configuration variables.
See http://book.cakephp.org/2.0/en/development/configuration.html#configure-class for more information.