HTML2PDF : error (sometimes) when generating, but PDF generated - magento2

Let me explain !
I have a magento website. I'm generating custom PDF when my user is making an order.
It works most of the time, but for some reason, sometimes, I have this error :
Undefined property: Spipu\Html2Pdf\MyPdf::$h in ...../vendor/spipu/html2pdf/src/MyPdf.php on line 670"
The line is this :
public function getH()
{
return $this->h;
}
The class is : class MyPdf extends \TCPDF
and in TCPDF, $h is a protected variable
It's weird, knowing that my PDF is saved on my server, and I can open without getting an error..
Do you have any idea of what the problem could be ?

Ah ah got it !
Forgot to mention, i'm using a loop to make and attach my pdf to a mailer.
I had to put the declaration of the HTML2PDF inside the loop, not outside (that's make sense).
Hope this will help !

Related

cakephp 3.0 'App\Controller\ContactForm' not found modelless form

I am trying to create a modelless form using cakePHP 3.0, I have been following the guide through the cookbook here http://book.cakephp.org/3.0/en/core-libraries/form.html but it seems I am getting confused as to where to put ContactForm.php. It says to put it in src/Form/ContactForm.php but it did not work. Can someone direct me to this? Thanks
Pls, provide a bit more info about your problem
1) is ContactForm recognized in controller?
if not - check namespace
2) handle your data only in
protected function _execute(array $data)
{
// Send an email.
return true;
}
not in controller's
if ($this->request->is('post')) {
if ($contact->execute($this->request->data)) {
//NOT HERE!!!
} else {
// error
}
}
Also bear in mind that your server configuration may forbid php short open tags.
Make sure your class starts with <?php and not only <? to be on the safer side. If not, CakePHP will simply respond by the Your\Namespace\Class Not Found message.
Just verify where you have put Form Folder, it must be inside src Folder.
Also be sure that the class has Form as suffix.
Because your error is App\Controller\ContactForm not found, that means that you have NOT put Form Folder inside src Folder.

how to refresh jstree with html instead rebuilding it

my code builds an html and initiates the jstree with that html :
var html = buildHtmlunorderedList()
$("#tree").html(html);
$("#tree").jstree({
"core":{"multiple":false},
"state":{"key":"vmsTree22"},
"plugins":["state","sort"]
}).bind("select_node.jstree",handleLeftClick);`
This work perfect.
now , every few minutes the html is built again and i want to refresh the jstree with it without the need to destroy it and initiate again (which cause a flick every time the tree is built again) :
inside a loop {
html = buildHtmlunorderedList();
var tree = $('#tree').jstree({
"core":{"data":html}
});
tree.refresh(true);
}
but i am getting an error : Uncaught TypeError: Cannot read property 'className' of undefined
(in jstree.js : var c = this.get_container_ul()[0].className;)
which seams it doesn't find the first children of class jstree-children.
what i am doing wrong ?
I didn't find any straight forward example of how to refresh the entire html of the tree without destroying it and build it again.
thanks for any help
You can replace data as below. Check demo - Fiddle.
$("#tree").jstree().settings.core.data = newData;
$("#tree").jstree().refresh(true);

neo4jphp: Cannot instantiate abstract class Everyman\Neo4j\Transport

maybe a simple question but for me as starter with Neo4j a hurdle. I installed the neo4jphp with composer in the same directory as my application. Vendor-Subfolder has been created and the everyman/neo4j folder below is available. For a first test I used this code snippet from the examples:
spl_autoload_register(function ($className) {
$libPath = 'vendor\\';
$classFile = $className.'.php';
$classPath = $libPath.$classFile;
if (file_exists($classPath)) {
require($classPath);
}
});
require('vendor/autoload.php');
use everyman\Neo4j\Client,
everyman\Neo4j\Transport;
$client = new Client(new Transport('localhost', 7474));
print_r($client->getServerInfo());
I always stumple upon the error
Fatal error: Cannot instantiate abstract class Everyman\Neo4j\Transport
Googling brought me to a comment from Josh Adell stating
You can't instantiate Everyman\Neo4j\Transport, since it is an abstract class. You must instantiate Everyman\Neo4j\Transport\Curl or Everyman\Neo4j\Transport\Stream depending on your needs
So I thought I just need to alter the use-statements to
use everyman\Neo4j\Client,
everyman\Neo4j\Transport\Curl;
but this doesnt work, debugging shows, that the autoloader only get "Transport.php" instead of "everyman\Neo4j\Transport\Curl.php". For "Client.php" its still working ("vendor\everyman\Neo4j\Client.php") so I am guessing that the use-statement is wrong or the code is not able to handle an additional subfolder-structure.
Using
require('phar://neo4jphp.phar');
works fine but I read that this is deprecated and should be replaced by composer / autoload.
Anyone has a hint what to change or had the same problem?
Thanks for your time,
Balael
Curl is the default transport. You only need to instantiate your own Transport object if you want to use Stream instead of Curl. If you really want to instantiate your own Curl Transport, the easiest change to your existing code is to modify the use statement to be:
use everyman\Neo4j\Client,
everyman\Neo4j\Transport\Curl as Transport;
Also, you don't need to register your own autoload function if you are using the Composer package. vendor/autoload.php does that for you.
Thanks Josh, I was trying but it seems I still stuck somewhere. I am fine with using the default CURL - so I shrinked the code down to
require('vendor/autoload.php');
use everyman\Neo4j\Client;
$client = new Everyman\Neo4j\Client('localhost', 7474);
print_r($client->getServerInfo());`
The folder structure is main (here are the files and the composer.json with the content
{
"require": {
"everyman/Neo4j": "dev-master"
}
}
and in the subfolder "vendor" we have the "autoload.php" and the subfolder everyman with the related content. When I run the file I come out with
Fatal error: Class 'Everyman\Neo4j\Client' not found
which does not happen when I have the autoloadfunction. I guess I made a mistake somewehere - can you give me a hint?
Thanks a lot, B
Hmmm... I was just trying around and it seems the Transport CLASS is not needed in the use-statement and the class instantiation. This seems to work:
require('vendor/autoload.php');
use everyman\Neo4j\Client;
$client = new Client();
print_r($client->getServerInfo());
also valid for having a dedicated server/port:
$client = new Everyman\Neo4j\Client('localhost', 7474);
If you have more input I would be happy to learn more - thanks, all input & thoughts are very appreciated.
Balael

Zend_validate isValid() get stuck fatalError Maximum execution time of 30 seconds exceeded in /library/Zend/Validate/Hostname.php on line 608

Iam suffering from Zend_validate ,when ever I write a form and try to add validators , the only thing that works for me if I submit the form with no values , it will show error msg , but if I submit good values it will stuck for sometime and then give fatal error msg saying Maximum execution time 30 seconds is exceeded in /Applications/MAMP/htdocs/MyApplicationFolderName/library/Zend/Validate/Hostname.php on line 608
Please help my controller action code is
public function createAction()
{
// action body
$roleService=new User_Service_RoleService($this->em);
$userForm=new User_Form_UserForm($roleService->listAllRoleNames());
$userForm->startForm();
$userForm->setAction('create');
$userForm->setMethod('post');
if($this->getRequest()->isPost() )
{
if($userForm->isValid($this->getRequest()->getPost()))
{
$this->userAccountService->createUser($this->getRequest()->getParams());
$this->_forward('confirm');
}
}
$this->view->form=$userForm;
}
and my form class code is
class User_Form_UserForm extends Zend_Form {
//put your code here
private $roles;
public function __construct($options = null) {
parent::__construct($options);
$this->roles=$options;
}
public function startForm()
{
$idForm=new Zend_Form_Element_Hidden('id');
$this->addElement($idForm);
///////////
$userEmailForm=new Zend_Form_Element_Text('email');
$userEmailForm->setRequired(TRUE);
$userEmailForm->setLabel('Email');
$emailValidator=new Zend_Validate_EmailAddress();
// $emailValidator->setOptions(array('domain' => FALSE));
$userEmailForm->addValidator($emailValidator,false);
$userEmailForm->setAttrib('size', 25);
$userEmailForm->setFilters(array(new Zend_Filter_StringToLower(),
new Zend_Filter_StringTrim())
);
$this->addElement($userEmailForm);
}
}
This is small part of my form its so simple but not working Iam using MAMP PHP 5.3.5 because of Doctrine2 and name spaces
Please any help will be really appreciated .
Note I also tried other validators like string length and the same error showed.
"I actually just found the answer to this one:
The version of PHP 5.3 that ships with MAMP has a bug in
iconv_strlen() that causes a "do { ... } while (false);" loop in the
validator to run infinitely. I just switched my PHP version to 5.2, as
it's closer to production anyway, and it works. If you need the 5.3,
though, you will have to upgrade your PHP installation in MAMP. I
haven't tried it, but the following link was highly recommended:
http://www.davidgolding.net/cakephp/upgrading-php-in-mamp.html
Hope that all helps."
Source: http://forum.mamp.info/viewtopic.php?f=2&t=12189
I worked out the problem by not using mamp , and start using Zendserver CE free Edition http://www.zend.com/en/products/server-ce/downloads
, and by going through the steps described on this link http://www.witheringtree.com/2011/07/installing-zend-server-ce-on-os-x-a-guide-for-the-terminal-timid/
I could edit my root document for zend server to USERS/sites/
I run Zendframework validation and it worked nicely , I like mamp but I develope on Zend and zend use iconv_strlen() ,
the other way to solve this issue is by installing PHP but I found that not an easy solution , or you can use macports and I didnot want to go that way, since Iam using zendframework I needed something related to it so I used zendServer which is so far the cleanest solution .

SilverStripe blog module translation

I noticed that the blog module for SS have hardcoded pieces of text - that I need to translate (in french). I found that the code is in /blog/templates/Includes/BlogSummary.ss but when I modify it, nothing changes on front-end...
I tried to run a /dev/build/?flush=all but nothing... still.
Any idea? Help would be much appreciated. Thanks in advance.
Have you set your locale? I recently set up a site in English & Spanish and used this setup.
// add similar code to your _config.php file
#Translatable::set_default_locale('en_US');
#Translatable::set_allowed_locales(array(
# 'en_US',
# 'es_US'
#));
Further, I had to add i18n::set_locale() code to the init() function in my content controller to get the template translations to work.
<?php
class SmartLanguageExtension extends DataObjectDecorator {
function contentcontrollerInit() {
i18n::set_locale(Translatable::get_current_locale());
}
}
In my case, I added an extension to the Page_Controller class for reusability later on.
// _config.php file
Object::add_extension('Page', 'SmartLanguageExtension');