Codeigniter - Problem while including env file - php

I'm trying to include .env file in Codeigniter 3 by following steps:
integrating.env files in CodeIgniter 3.0 using hooks
But, it returns the following error
A PHP Error was encountered Severity: 4096
Message: Argument 1 passed to Dotenv\Dotenv::__construct() must be an
instance of Dotenv\Loader, string given, called in
/application/config/hooks.php on line 5 and defined
Filename: src/Dotenv.php
Line Number: 31
My /application/config/hooks.php file is configured in the same way as indicated in the tutorial:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
$hook['pre_system'] = function() {
$dotenv = new Dotenv\Dotenv(APPPATH);
$dotenv->load();
};
I had done a quick research and unable to find a perfect solution for the problem occurred, Can you guys please help me to find out a solution?

I was able to install phpdotenv in a different way from the instructions in the first tutorial.
In this tutorial installation is done without the use of Composer:
PHPDotenv for CodeIgniter (Installation without Composer)

If you try something like that :
$dotenv = Dotenv\Dotenv::create(__DIR__);

I assume the vendor folder is in project/vendor, not inside project/application/vendor folder. Then try this:
$hook['pre_system'] = function() {
$dotenv = Dotenv\Dotenv::create(FCPATH);
$dotenv->load();
};

Related

Fzaninotto Faker PHP Fatal Error

I keep getting this error when I am trying to test Faker PHP from github on my server:
Fatal error: Class 'Faker\Provider\en_US\Address' not found in /home/andrew/public_html/JeffWork/src/Faker/Provider/en_US/Address.php on line 6
Link: http://aswanson.net/JeffWork/test/test.php
All of the package files have been installed and uploaded properly, and the code on line 5 & 6 looks like:
class Address extends \Faker\Provider\en_US\Address
{
Please make sure whether the file exists in the folder where your referring for "/home/andrew/public_html/JeffWork/src/Faker/Provider/en_US/Address.php".
Please take a new update with composer with the following
composer require fzaninotto/faker
Now with the updated version 1.6, you will be able to solve this kind of issue make sure to use autoload.php in file where your using.
The following shows the snippet of usage
<?php
require_once 'vendor/autoload.php';
$faker = Faker\Factory::create();
$person = new Faker\Provider\en_US\Person($faker);
$address = new Faker\Provider\en_US\Address($faker);
foreach(range(1,10) as $i){
echo $address->address(),'<br/>';
}
Cheers!

How to setup a php client Thrift 0.9.1 ...

I'm trying to setup a php client for RPC with a HBase Thrift server but I'm getting some errors at the begining ... I've compilated the HBase.thrift file (with the 0.9.1 compiler) and I've put the 2 generated files like bellow (/ is the root of my project, I'm using apache server on ArchOS) :
/include/Hbase.php
/include/Types.php
I've included the lib folder of thrift0.9.1/lib/php/lib (composed of Thrift and sub folders) under / and so I've the following file system :
/include/HBase.php
/Types.php
/Thrift/Base
/ClassLoader
/Exception
/ext
...
To be able to use my service (HBase.php) I've to load files so my code is the following :
<?php
$GLOBALS['THRIFT_ROOT'] = PHYSICAL_PATH;
// Load up all the thrift stuff
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TSocket.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Protocol/TProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Protocol/TBinaryProtocol.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Transport/TBufferedTransport.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Type/TMessageType.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Factory/TStringFuncFactory.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/StringFunc/TStringFunc.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/StringFunc/Core.php';
require_once $GLOBALS['THRIFT_ROOT'].'Thrift/Type/TType.php';
use Thrift\Protocol\TBinaryProtocol;
use Thrift\Transport\TSocket;
use Thrift\Transport\TSocketPool;
use Thrift\Transport\TFramedTransport;
use Thrift\Transport\TBufferedTransport;
//hbase thrift
require_once ('Hbase.php');
require_once ('Types.php');
?>
When I'm charging the different files, I'm getting an error for this line --require_once ('Types.php');-- and the error is : Fatal error: Class 'Thrift\Exception\TException' not found in /var/www/html/POCThrift2/include/Types.php on line 1266
I understand it like : When I tried to include Types.php, the Thrift\Exception\TException namespace was not use (despite the use Thrift\Exception\TException; in the beginig of the Types file) but I don't know why I'm getting his error ... can you help me ? Does anyone has encountered this problem before ? Thx in advance, I'm stuuuck right now ...

Fatal error installing Twiggy with Codeigniter/HMVC

when trying to install twiggy with codeigniter/HMVC I get the following error:
A PHP Error was encountered
Severity: Notice
Message: Undefined property: CI::$twiggy
Filename: MX/Controller.php
Line Number: 58
I have installed twiggy as described on http://edmundask.github.io/codeigniter-twiggy/
The only thing I did was change the name of the spark MY_Loader.php to MY_Spark_Loader.php because it had the same name as the HMVC MY_Loader.php
I have autoloaded twiggy in the autoload.php like this:
$autoload['sparks'] = array('twiggy/0.8.5');
My controller looks like this:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Test extends MX_Controller
{
public function index()
{
$this->twiggy->display();
}
}
Any help to get this running would be much appreciated!
Make sure that the autoloader is pointing to the correct location. Mine looks like this: $autoload['sparks'] = array('../tools/sparks/Twiggy/0.8.5');
Did you follow this instruction
http://getsparks.org/set-up-mx
It explains how to install spark manager with hmvc, but there is a bug, if you run $this->router->fetch_modules() in modules which is run from another module it doesn't return current running module, it returns original module.
To fix that, don't replace MX/Loader.php with the one provided there, just use hmvc original file, but add two functions to load sparks from that loader to hmvc loader file.
For MX/Modules.php do the same thing, just take spark specific code to hmvc original file.
Sorry for my bad english. Hope you understand

Using Unirest php lib that has a namespace

I'm trying to use unirest, a new php lib for making rest calls.
I'd like to place it in a system-wide directory above my project. I then include it:
require_once ('../unirest-php-master/lib/Unirest/Unirest.php');
loads fine. Then I use it per the readme:
$response = Unirest::post(CSWA_URL ....
I get Fatal error: Class 'Unirest' not found in ...hello_world/sign_start.php on line 23
I then try to use the namespace (see the library's code. They use a Namespace Unirest statement before declaring the Unirest class.)
$response = Unirest\Unirest::post(CSWA_URL ....
I got further. Now: Fatal error: Class 'Unirest\HttpMethod' not found in ....unirest-php-master/lib/Unirest/Unirest.php on line 26 -- This is an error in the library code!
Q: Did I do something wrong? Did the authors of Unirest make a mistake? Do I have to place the library in ./lib? What's the best fix?
It looks like the Unirest code in Unirest.php relies on autoloading code from the two other files in the unirest lib directory (HttpMethod.php and HttpResponse.php).
The author suggests installing the package using composer, if you were to do that composer would add the Unirest namespace to the autoloader.php script it generates. From there you need to require the autoload.php file at the top of your script and it will handle loading classes that aren't defined.
Alternatively, if you don't want to use composer, I would just require the other two files in the unirest lib directory at the top of your script as well.

Symfony Class Not Found

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

Categories