I'm trying to create a new Extension on Extbase in TYPO3 6.2 and im failing at including an existing Class/Framework Module.
My ext_autoload.php (ofc located in my extension dir)
$extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('couponprinter');
return array(
'ZendPdf' => $extensionPath . '/Classes/Utility/Zend/Pdf.php',
);
I'm trying to load the class in my controller via
$pdf = $this->objectManager->create('ZendPdf');
But im gettin the error "Could not analyse class:ZendPdf maybe not loaded or no autoloader?"
The Zend class itself has tons of includes which I cant refactor all, so I need the autoloader. Here is a short snippet:
/** Internally used classes */
require_once 'Zend/Pdf/Element.php';
require_once 'Zend/Pdf/Element/Array.php';
require_once 'Zend/Pdf/Element/String/Binary.php';
require_once 'Zend/Pdf/Element/Boolean.php';
require_once 'Zend/Pdf/Element/Dictionary.php';
require_once 'Zend/Pdf/Element/Name.php';
require_once 'Zend/Pdf/Element/Null.php';
require_once 'Zend/Pdf/Element/Numeric.php';
require_once 'Zend/Pdf/Element/String.php';
class Zend_Pdf{
// code of the class
}
Since TYPO3 6.2 changed some old methods, I can't include anymore. Does anyone have a idea how I can load a not-namespaced class into a extbase extension?
You need to create a ext_autoload.php file and fill it with something like
<?php
$extensionClassesPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('news') . 'Classes/';
$default = array(
'tx_news_domain_model_dto_emconfiguration' => $extensionClassesPath . 'Domain/Model/Dto/EmConfiguration.php',
'tx_news_hooks_suggestreceiver' => $extensionClassesPath . 'Hooks/SuggestReceiver.php',
'tx_news_hooks_suggestreceivercall' => $extensionClassesPath . 'Hooks/SuggestReceiverCall.php',
'tx_news_utility_compatibility' => $extensionClassesPath . 'Utility/Compatibility.php',
'tx_news_utility_importjob' => $extensionClassesPath . 'Utility/ImportJob.php',
'tx_news_utility_emconfiguration' => $extensionClassesPath . 'Utility/EmConfiguration.php',
'tx_news_service_cacheservice' => $extensionClassesPath . 'Service/CacheService.php',
);
return $default;
?>
Found in the documentation at http://docs.typo3.org/typo3cms/CoreApiReference/ApiOverview/Autoloading/Index.html
I guess it should be
$extensionPath = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::extPath('couponprinter');
return array(
'zendpdf' => $extensionPath . '/Classes/Utility/Zend/Pdf.php',
);
The left side of the array (keys) must be lowercase.
Related
Some years ago I made a Drupal 7 site. I want to remake the site with Drupal 9.
In Drupal 7 I added nodes programmatically with this PHP code:
<?php
define('DRUPAL_ROOT', getcwd());
require_once DRUPAL_ROOT . '/includes/bootstrap.inc';
drupal_bootstrap(DRUPAL_BOOTSTRAP_FULL);
$data = $_GET['d'];
AddNewNode($data);
function AddNewNode($data)
{
list($installlanguage, $playerid) = explode('|', $data);
$node = new stdClass();
$node->type = 'new_install';
node_object_prepare($node);
$node->language = LANGUAGE_NONE;
$node->field_hm_new_installlanguage[$node->language][0]['value'] = $installlanguage;
$node->field_hm_new_install_playerid[$node->language][0]['value'] = $playerid;
node_save($node);
}
?>
This code isn't working with Drupal 9.
I tried to search Google for "drupal 9 add content programmatically", but I don't seem to get any useful results. Most links are about Drupal 8.
Can someone point me in the right direction?
Thank you!
You can still do this if you really want. However, there are much better ways of managing content creation now (look at the examples for "migrate" module with e.g. JSON or CSV files).
The equivalent of what you have previously would be something like this;
<?php
use Drupal\Core\Database\Database;
use Drupal\Core\DrupalKernel;
use Symfony\Component\HttpFoundation\Request;
$autoloader = require_once 'autoload.php';
$request = Request::createFromGlobals();
$kernel = DrupalKernel::createFromRequest($request, $autoloader, 'prod');
$kernel->boot();
defined('DRUPAL_ROOT') or define('DRUPAL_ROOT', getcwd());
$node = \Drupal::entityTypeManager()->getStorage('node')->create([
'type' => 'article',
'title' => 'something something',
'langcode' => 'en',
'field_something' => ... // Check the structure as it differs between fields.
]);
// You don't have to do it all in one array.
$node->set('field_something_2', 'something');
$node->save();
Take a look here for more information https://drupalbook.org/drupal/9111-working-entity-fields-programmatically.
According to this blog post,
the code is simpler (compared to #Pobtastic's answer) when you use it within a Drupal PHP page:
use Drupal\node\Entity\Node;
$node = Node::create([
'type' => 'article',
'langcode' => 'en',
'title' => 'My test!',
'body' => [
'summary' => '',
'value' => '<p>The body of my node.</p>',
'format' => 'full_html',
],
]);
$node->save();
\\ Add URL alias :
\Drupal::service('path.alias_storage')->save("/node/" . $node->id(), "/my/path", "en");
Source:
I installed ciphersweet on my server using composer but when i try to import the library i'm getting this error.
Fatal error: Uncaught Error: Class 'ParagonIE\CipherSweet\KeyProvider\StringProvider' not found in index.php.
Seems like the dependency didn't install correcty, i'm lost can you help please.
It's a php error.
here's my code :
use ParagonIE\CipherSweet\EncryptedRow;
use ParagonIE\CipherSweet\Transformation\AlphaCharactersOnly;
use ParagonIE\CipherSweet\Transformation\FirstCharacter;
use ParagonIE\CipherSweet\Transformation\Lowercase;
use ParagonIE\CipherSweet\Backend\FIPSCrypto;
use ParagonIE\CipherSweet\KeyProvider\StringProvider;
$provider = new StringProvider('a981d3894b5884f6965baea64a09bb5b4b59c10e857008fc814923cf2f2de558');
$engine = new CipherSweet($provider, new FIPSCrypto());
/** #var CipherSweet $engine */
$row = (new EncryptedRow($engine, 'contacts'))
->addTextField('first_name')
->addTextField('last_name')
->addFloatField('latitude')
->addFloatField('longitude');
// Notice the ->addRowTransform() method:
$row->addCompoundIndex(
$row->createCompoundIndex(
'contact_first_init_last_name',
['first_name', 'last_name'],
64, // 64 bits = 8 bytes
true
)
->addTransform('first_name', new AlphaCharactersOnly())
->addTransform('first_name', new Lowercase())
->addTransform('first_name', new FirstCharacter())
->addTransform('last_name', new AlphaCharactersOnly())
->addTransform('last_name', new Lowercase())
);
$prepared = $row->prepareRowForStorage([
'first_name' => 'Jane',
'last_name' => 'Doe',
'latitude' => 52.52,
'longitude' => -33.106,
'extraneous' => true
]);
var_dump($prepared);
?>
You need to load the vendor/autoload.php in order for the installed packages to work.
For example, add require_once __DIR__ . '/vendor/autoload.php'; to the top of your file.
This will make php aware of the namespaces in your packages.
You might need to change this if your files are not in the root directory of your application. For example, if your files are in app/ directory, those files need to use require_once __DIR__ . '/../vendor/autoload.php'
See https://getcomposer.org/doc/01-basic-usage.md#autoloading for more details.
I use the plugin 'blueimp jquery fileupload' to upload files in Javascript (that part I got it right) and then I have to handle the uploads on the server side using an uploadhandler affiliated to the plugin (UploadHandler.php).
Working in Symfony, I managed to create a service based on this php script and it works in my controller (the files are uploaded in the default repository, yet on my page I get the error message 'upload failed' and I don't know why but it's not a big problem I guess), but the thing is :
I would like to custom the repository path to upload the files based on the user id, and since I call the uploadhandler file as a service, I don't know how to override the options using the construct function, as I would be able to with a basic call in php.
Here's my code :
public function uploadFiles(Request $request)
{
$uploadhandler = $this->container->get('extranetcontratbundle.uploadhandler');
$response = $uploadhandler->response;
$files = $response['files'];
return new JsonResponse($files);
}
In the options of UploadHandler.php there is :
$this->options = array(
'script_url' => $this->get_full_url().'/'.$this->basename($this->get_server_var('SCRIPT_NAME')),
'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'/files/',
'upload_url' => $this->get_full_url().'/files/',
'input_stream' => 'php://input',
'user_dirs' => false,
'mkdir_mode' => 0755,
'param_name' => 'files',
...blabla
And I would like to override the options in a similar way as I would in 'normal' php :
$tmpImagesDir = JPATH_ROOT . 'tmp' . $userId .;
$tmpUrl = 'tmp/' . $userId . '/' . '/';
$uploadOptions = array('upload_dir' => $tmpImagesDir, 'upload_url' => $tmpUrl);
$uploadHandler = new UploadHandler($uploadOptions);
But to do that I would have to write "require_once(blabla)" and I would have created the service for nothing. If I understood it right, that's not the way to do it in Symfony. Is there a way ?
Thank you for reading, please help.
I just installed Zend Service Amazon 2.0.3 with composer.
Amazon Packagist here
Composers worked fine and the S3's dir is:
vendor:
------>zendframework:
------------->zendservice-amazon:
---------------------------->library:
---------------------------------->ZendService:
---------------------------------------------->Amazon:
------------------------------------------------------>S3:
within autoload_namespaces.php file:
$vendorDir = dirname(dirname(__FILE__));
$baseDir = dirname($vendorDir);
return array(
'Zend\\' => array($vendorDir . '/zendframework/zendframework/library'),
'ZendXml' => array($vendorDir . '/zendframework/zendxml/library'),
'ZendService\\Amazon\\' => array($vendorDir . '/zendframework/zendservice-amazon/library'),
'ZendRest' => array($vendorDir . '/zendframework/zendrest/library'),
);
I don't understand to use S3 class. I tried to use:
$s3 = new ZendService\Amazon\S3($k1, $k2);
or
use ZendService\Amazon;
$s3 = new ZendService\Amazon\S3($k1, $k2);
or
use ZendService\Amazon\S3;
$s3 = new Amazon\S3($k1, $k2);
or
use ZendService\Amazon\S3;
$s3 = new S3($k1, $k2);
but the errors are like this:
Fatal error: Class 'ZendService\Amazon\S3' not found in C:\Program Files (x86)\xampp\htdocs\my-site\module\Upload\src\Upload\Controller\UploadController.php on line 38
how can I use S3 class?
I done it
$s3 = new \ZendService\Amazon\S3\S3($AccKey, $SecrKey);
but I don't doing anything! example,
$s3->createBucket('my-bucket-name-is-secret', 'eu-central-1');
apparently doesn't appear any error, but if I check in my s3's console, there isn't any bucket.
I'm trying to make Slim work with Twig template system, this is part of my index.php
// Twig [Template]
require 'Extras/Views/Twig.php';
TwigView::$twigDirectory = __DIR__ . '/vendor/Twig/lib/Twig/';
//Slim
require 'Slim/Slim.php';
\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim(array(
'view' => $twigView
));
And this is my structure
Extras
|_Views
|_Twig.php
Slim
templates
vendor
|_Twig
|_lib
|_Twig
index.php
I try several times with other configurations and searching buy I ALLWAYS get this error:
Fatal error: Class 'Slim\View' not found in C:\wamp\www\slim\Extras\Views\Twig.php on line 43
Can anyone help me here? All the examples I had found was using composer
Ok, I solve it.
This is the solution:
// Slim PHP
require "Slim/Slim.php";
\Slim\Slim::registerAutoloader();
// Twig
require "Twig/lib/Twig/Autoloader.php";
Twig_Autoloader::register();
// Start Slim.
/** #var $app Slim */
$app = new \Slim\Slim(array(
"view" => new \Slim\Extras\Views\Twig()
));
And this is my structure now.
Slim
|_Extras
|_Views
|_Twig.php
|_Slim
templates
Twig
|_lib
|_Twig
|_Autoloader.php
index.php
¡I hope this help someone else!
Now Slim-Extras is DEPRECATED, we must use Slim-Views (https://github.com/codeguy/Slim-Views):
require "Slim/Slim.php";
\Slim\Slim::registerAutoloader();
$slim = new \Slim\Slim( array(
'debug' => false,
'templates.path' => 'fooDirTemplates',
'view' => '\Slim\Views\Twig'
));
$twigView = $slim->view();
$twigView->parserOptions = array(
'debug' => false
);
$twigView->parserDirectory = 'Twig';
$twigView->parserExtensions = array(
'\Slim\Views\TwigExtension'
);
$slim->notFound( 'fooNotFoundFunction' );
$slim->error( 'fooErrorFunction' );
// SLIM routes...
$slim->run();
If someone is still running in to this issue.
The problem for me was that I had installed both slim/views AND slim/twig-view.
I uninstalled slim/views and it worked