I am using the duncan3dc module in laravel, Successfully importing text from the default example But I do not know how to take a screenshot,
I just installed this module using Composer.
$ composer requires duncan3dc/dusk.
Does it mean that everything needed for this module is automatically installed?
Or do I need something else to take a screenshot?
Below is my controller code
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use duncan3dc\Laravel\Dusk;
class TestController extends Controller
{
public function test()
{
$dusk = new Dusk;
$dusk->visit("http://example.com");
$dusk->screenshot("ddd");
echo $dusk->element("h1")->getText() . "\n";
}
}
When I run the above code, I get this error:
file_put_contents (/tmp/ddd.png): failed to open stream: No such file
or directory
I think there is no folder, so I get the error, where should I create the folder in the project folder?
According to the changelog from version 0.8.0 you can pass fully qualified path to screenshot method. So doing this will work (you should see the file ddd.png created near the php file):
$dusk = new Dusk;
$dusk->visit("http://example.com");
$dusk->screenshot("./ddd.png");
echo $dusk->element("h1")->getText() . "\n";
You can also pass absolute path:
$dusk->screenshot("C:\windows\temp\ddd.png"); // if you are using windows
or
$dusk->screenshot("/tmp/ddd.png"); // if you are using macos/linux
Related
I want to use namespaces class to manual one without using autoload.php to be included. Because I don't want to use all function the class.
I am using this project https://github.com/codenix-sv/coingecko-api to get it's function in my php function.
In the example of using is like this
use Codenixsv\CoinGeckoApi\CoinGeckoClient;
$client = new CoinGeckoClient();
$data = $client->ping();
But I want to change it to require_once. So I put all src folder in my php folder and create this to call the function
require_once 'libs/Api/CoinGeckoClient.php';
$client = new Codenixsv\CoinGeckoApi\CoinGeckoClient;
$data = $client->simple();
First I got this error when trying to access the page.
Fatal error: Uncaught Error: Class 'GuzzleHttp\Client' not found in
C:\xampp\htdocs\te.st\libs\Api\CoinGeckoClient.php:35
Then I try to remove the line "use GuzzleHttp\Client" in CoinGeckoClient.php file.
And got with this error
Fatal error: Uncaught Error: Class 'Codenixsv\CoinGeckoApi\Client' not
found in C:\xampp\htdocs\te.st\libs\Api\CoinGeckoClient.php:35
Is there any way to just use the "simple" function of coingecko only in my php file.
https://github.com/codenix-sv/coingecko-api/blob/master/src/Api/Simple.php
Here is the way I fix this.
load in composer.json like
{
"require": {
"codenix-sv/coingecko-api": "^1.0",
"guzzlehttp/guzzle": "~6.0"
}
}
then do composer update in command window.
In my php file. make sure
use Codenixsv\CoinGeckoApi\CoinGeckoClient;
is placed in top of file. Then do the rest.
Thanks all
That package is prepared to works with composer.
Composer delivered autoloader, to make you work simplier.
If you remove use GuzzleHttp\Client line from CoinGeckoClient.php, there will be no way to send request to the server.
The best option is include composer autoload in your project file, it means you should:
Create composer.json file for you project
Add required library dependency using command: composer require guzzlehttp/guzzle
Add require library dependency using command: composer require codenix-sv/coingecko-api
Inside your project file add folowing line:
require_once(dirname(__FILE__) . '/vendor/autoload.php');
use Codenixsv\CoinGeckoApi\CoinGeckoClient;
$client = new CoinGeckoClient();
$data = $client->ping();
In other way, that will be necessarily to import all files manually. And of course, you haven't to forget about imports for Guzzle client.
I am using Laravel 6.5.2 and trying to use the package "Requests for PHP". https://requests.ryanmccue.info/download/
I installed this package using composer. The reason I want to use this packages is that I have all CRUD scripts created (using above package) and would like to reuse the scripts.
I suspect there might be some name conflict since Laravel comes installed with a HTTP request solution called Request, meanwhile the [PHP Request] has the same name.
Question:
Has anyone succesfully installed [Requests for PHP] package and got it to work with Laravel 6.X ?
Other findings:
Whe comment-out the autoloader line, the corresponding page prints "hello" as it should. Leaving this line active indicates in the laravel stack trace that the error is the line that holds the autoloader.
[Error]
Class 'App\Http\Controllers\Requests' not found
[routes/web.php]
Route::get("/requests", "Requests#read");
[app/Http/Controllers]
<?php
namespace App\Http\Controllers;
// use Illuminate\Http\Request; // Standard line, creeating a controller.
require_once '../vendor/rmccue/requests/library/Requests.php';
Requests::register_autoloader();
class Requests extends Controller {
public function read() {
echo "hello";
}
}
I want to use this php library "Math-php-master" in my php script.
it is using namespaces.
My script is outside the library folder and the folder for the library is "MathPHP"
There is a php file "Finance.php" which I want to access.
path is "MathPHP/Finance.php". finance.php is using namespace MathPHP
and there is function irr() inside Finance.php which I need.
My code for accessing in my script is below:
include 'MathPHP/Finance.php';
use MathPHP\Finance;
$s = new MathPHP\Finance;
$val = $s->irr(array);
but when I run the script it is giving error "Uncaught Error: Class 'MathPHP\Finance' not found"
I tried everything, I tried the code given on github by the author but it is not working at all
link to the library on github: https://github.com/markrogoyski/math-php
Please help me.
thanks
You have not gone through the effort of readying the readme on how to use the library. In PHP most projects use composer and its autoloading to load classes.
Install composer if you do not have it https://getcomposer.org/doc/00-intro.md#installation-linux-unix-osx
In short as the documentation suggests do
php composer.phar require markrogoyski/math-php:0.*
And in your code
require_once(__DIR__ . '/vendor/autoload.php');
use MathPHP\Finance;
// the rest of the code here
I am trying to use PhantomJs in my laravel 5 project. I have downloaded via composer. I have added into my providers section and aliases section within config/app.php
Okay so i have now created my controller as seen below:
<?php namespace App\Http\Controllers;
use App\Http\Requests;
use PDF;
use View;
class PdfController extends Controller {
public function index()
{
$view = View::make('home');
return PDF::createFromView($view, 'home.pdf');
}
}
I have also created my route for this method. However when i try this in my browser it throws the following error:
PhantomJS: sh: /Users/matts/sites/ManagementApp/vendor/antking/phantom-pdf/src/../bin/phantomjs: cannot execute binary file
Has anyone come across this before?
Thanks
The "cannot execute binary file" indicates that it was not able to run phantomjs at all, and it is probably not related to your code. The most likely reason for this is an architecture incompatibility. Depending on whether or not you have a 32 or 64 bit system, you should use either phantomjs-1.9.8-linux-x86_64 (64bit) or phantomjs-1.9.8-linux-i686. It is possible that you used the wrong one for your system.
I am getting the error:
PHP Fatal error: Class 'Symfony\\Component\\Process\\PhpProcess' not found in ...
It's my first time using Symfony. I download the files from the GitHub site. Since the downloaded files are of the Process directory, I created folders in order to have the correct path. (Symfony/Component/Process/DOWNLOADED FILES).
I placed the Symfony directory in the main directory (where my index file is).
Is this how you install Symfony? (Note I only need the Process sub-directory and not the whole framework)
For now I am using this ready-made code, just to see if I can get it running:
use Symfony\Component\Process\PhpProcess;
$command = file_get_contents('/hello_world.php');
if ( $command ) {
$process = new PhpProcess($command); //<----- GETTING ERROR HERE
$process->run();
if ($process->isSuccessful()) {
$output = $process->getOutput();
// ...
}
else {
throw new Exception($process->getErrorOutput());
}
}
Why am I getting this error and how can I fix it please? Is it due to a bad path?
I think it has to do with namespace registration, have you checked that the namespace that defines the class is loaded?, check the ClassLoader reference
Check the autoload.php file inside your app directory