Call to a member function stream() on string Barryvdh\DomPDF - pdf

Trying to create PDF from HTML and storing it to AWS bucket in Laravel using Barryvdh\DomPDF. It works fine, the pdf is created and is stored to aws bucket but getting error , Call to a member function stream() on string.
All this process is called through a queue job, the error response is saved to failed_jobs table in exception field in DB.
Below is the snippet code used.
$fileName = "anyfilename.pdf"
$html = \View::make('frontend.courses.certificate', [
'course' => "This is test course",
])->render();
$pdf = \PDF::setPaper('a4', 'landscape')->loadHtml($html);
\Storage::disk('s3')->put($s3Path, $pdf->stream($fileName)->getContent());
I have tried to solve this but nothing works. Any suggestions how to bebug this or any fix for this.

Related

Illegal offset type in isset or empty

Current PHP version: 7.1.7
please help me I have this problem
Illegal offset type in isset or empty at line 113
I have this problem after I decided to upload files to my website
in C:\xampp\htdocs\archive\vendor\yiisoft\yii2\web\UploadedFile.php
line 113:
public static function getInstanceByName($name)
{
$files = self::loadFiles();
return isset($files[$name]) ? new static($files[$name]) : null;
}
and guys if this not clear ask me for more explication and thanks
This code in models
[['file'],'file'],
this code in controllers
$docfileload = $model->docname;
$model->file = UploadedFile::getinstancebyname($model,'file');
$model->file->saveAs('uploads/'.$docfileload.'.'.$model->file->extension);
$model->save();
//save path in db
$model->docfile = 'uploads/'.$docfileload.'.'.$model->file->extension;
this code in _form
<?= $form->field($model,'file')->fileinput(); ?>
in first I used getInstance() but replecd getInstanceByName() because had porblem here
error yii2 upload Call to a member function saveAs() on null
Illegal offset type errors occur when you attempt to access an array index using an object or an array as the index key.
You function is defined as getInstanceByName($name), but you are calling it using getinstancebyname($model,'file')
Something wrong there
in first I used
$model->file = UploadedFile::getinstancebyname($model,'file');
but right is to use
$model->file = UploadedFile::getinstance($model,'file');

Accessing json document keys in adapter procedure (IBM worklight)

I have a local jsonstore linked to a remote sql database through an adapter. I am trying to push local data to the remote database like this :
submit_data = function () {
accessor.getPushRequired().then(function (result) { alert(result.length);
accessor.push();
});
Let us say I only added documents (no replace/remove).
I want my add procedure to look like this:
function addGegegr(document) {
//WL.Logger.warn(document[56]);
return WL.Server.invokeSQLStoredProcedure({
procedure : "DBO.USP_TIM_add_sp",
parameters : [document.key1,document.key2,document.key3,...]
});
}
And same for the replace/remove procedure, they should be calling other stored procedures with the same parameters.
However, I get errors because it seems the variable "document" worklight is passing to the add function after push is called is just a string and not a json object.
So my question is : how do I access the json attributes from the adapter procedure? If not possible, can I pass those attributes to the push function?
P.S.: passing each of the n documents to add as parameter of push() does not work and causes add to be called n*n times instead of n...
Try using JSON.parse to turn the string into a JavaScript object.
function addGegegr(document) {
var doc = JSON.parse(document);
//... use doc as a regular JavaScript object
}
If JSON.parse is not available there, you can add it by including this code in the adapter implementation file.

Uploading a file with custom generated symfony 1.4 forms

I use a module that creates customized html forms through template partails
I need to manage 4 file uploads of a form.
In actions I pull all field data like so:
$allData = $request->getParameterHolder()->getAll();
which would get me the uploaded file name, but I need to also save that file to the uploads dir.
I am trying to bind the form like so:
if( isset($customData['getAttachments']) && count($allData)){
$attachments = $formInput->bind($request->getParameter('forms_input'), $request->getFiles('forms_input'));
}
which succesfully generates the $attachments object. Sanity check on that is a var_dump($attachments);die; which dumps:
object(FormsInput)#225 (18) { ["_node":protected]=> NULL ["_id":protected]=> array(1) { ["id"]=> string(5) "32171" } ["_data":protected]=> array(6) { ["id"]=> string(5) "32171" ["form_uid"]=> string(32) "aef79b2d47722ca154788cc9c8f8de2b" ["data_array"]=> string(770) "a:20:{s:9:...
How to I extract the file and push to a directory. I tried this:
$file = $attachments->getValue('file');
if($file) {
$filename = sha1($file->getOriginalName()).$file->getExtension($file->getOriginalExtension());
$file->save(sfConfig::get('sf_upload_dir').'/'.$formTitle.'/'.$usrDir.''.$filename);
}
but it throws this error:
Unknown record property / related component "value" on "FormsInput"
How can I get the uploaded into a sf dir?
UPDATE
Tried to use the sfValidatorFile class, but I cannot figure out how to pass it the parameters from the $attachment object:
$file = new sfValidatorFile();
if($file) {
$filename = sha1($file->getOriginalName()).$file->getExtension($file->getOriginalExtension());
$file->save(sfConfig::get('sf_upload_dir').'/uploadedDir');
}
throws this:
Fatal error: Call to undefined method sfValidatorFile::save()
What you intended to do with the $file->save requires an sfValidatedFile object.
If FormsInput is an instance of sfFormObject, you can configure your form with 4 sfValidatorFile with the path you wanted in option. It will do the job you need.

Does a foreach loop work directly with a JSonStore data object store?

I create a JSonStore with a JSON formatted array of objects.
I have verified it is properly formatted.
I then try to use a dojo forEach loop on it but the JSonStore doesn't seem to have any data in it. I can specify the target in my web page URL and it shows the right data. But using console.log(myJsonStore) shows an object but I don't see the data in Firebug. I also don't see any GET for the service providing the data. It's like specifying the target path in a URL in the browser fires the GET but not when I try to trigger it in the postCreate where my foreach is located.
The answer from Ricardo, i believe is a little incorrect, seeing as the JsonRest.query function returns a dojo.Deferred.
You have a REST call being made asynchroniously through store read api - and once it returns values, it will promise to run whats set as the callback.
Try this for your loop iterator instead
storeObj.query( {} ).then(function ( results ) {
dojo.forEach( results, function( obj ) {
console.log( obj );
});
}
you can do this:
var storeObj = new JsonRest({
target: "/some/resource"
});
storeObj.query({}).forEach(function(obj){console.log(obj);});
that should do the trick

Linqpad - Outputting into anchor to use title

I have a db that stores exception messages.
I would like to create a query that gets these exceptions but instead of dumping huge amounts of text i would prefer it to be "on demand".
I figured putting the exception into an anchor tag like so and then reading the message when needed by mousing over it would work... apparently not.
var logsForErrors = (from error in Logs
select new {
error = LINQPad.Util.RawHtml("<a title='"+ error.Exception+"'></a>"),
errorDate = error.Date,
errorMessage = error.Message
}).Take(10);
logsForErrors.Dump();
This is throwing an exception (lol) - "Cannot parse custom HTML: "
Encoding the exception message
...RawHtml("<a title='"+ Uri.EscapeDataString(error.Exception)+"'></a>")
Message Could not translate expression 'RawHtml((("h__TransparentIdentifier0.error.Exception)) +
"'>"))' into SQL and could not treat it as a local expression.
will generate a new error
Any ideas? - I am open to alternative solutions to this also.
I just want a container for the message instead of it just dumping right into the output as it it so huge!.
Thanks,
Kohan
Have you tried using the "Results to DataGrids" mode in the recent betas? It might do just what you need without having to write anything else.
Edit: your error was probably due to emitting HTML without escaping the text. The easiest solution is to call Util.RawHtml with an XElement instead of a string. You could write an extension method that does what you want like this:
public static class Extensions
{
public static object Tooltipize (this string data)
{
if (string.IsNullOrEmpty (data) || data.Length < 20) return data;
return Util.RawHtml (new XElement ("span", new XAttribute ("title", data), data.Substring (0, 20)));
}
}
Put this into My Extensions and you can use it from any query.