There is no issues encountered on local developement. Once got live/production, the problem came out with class not found errors.
System Backbone and Library
Dompdf 0.7.x#beta for both local and production
Codeigniter 3.0
Local development
Windows 8.1
PHP 5.6.3
Production Environment
Ubuntu 14.0 LTS
PHP 7
As Dompdf prior to version 7 and above, i'm using namespace in my controller. Here is the step of installations.
Installing dompdf using composer
Upon successful Vendor directory was created at the root of project
I'm auto loaded composer's autoload.php file by set the path inside application/config/config.php eg : $config['composer_autoload'] = './vendor/autoload.php';
Then i call the dompdf namespace at my controller like so : use Dompdf\Dompdf;
And last, at one of my class's method, i'm instantiated the class with : new DOMPDF();, also try with new \DOMPDF(); and new Dompdf(); but all of these failed.
Sample code
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
use Dompdf\Dompdf;
class App extends CI_Controller {
public function testPdf() {
$dompdf = new DOMPDF();
//------------ All failed
// $dompdf = new \DOMPDF();
// $dompdf = new Dompdf();
// $dompdf = new \Dompdf();
// $dompdf = new Dompdf\Dompdf\Dompdf();
}
.........
.........
Anyone encountered this?
Related
I am trying to make a Codeigniter 3 application to authenticate to a CAS server.
I installed the phpcas package with composer but I cant find any details or examples on how to do this. I want the access to this application to be only from authentication users.
I believe that I have to edit a config file but I cant find any to write down the cas server url, etc. Also, in the controller of the page, I have to call somehow the library but I need some example for that.
So the main question is how can i get to use phpcas inside my controller methods amd how to configure it?
I created a controller and have inside:
?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class AuthController extends CI_Controller {
public function actionLogin()
{
$this->module->casService->forceAuthentication();
$username = $this->module->casService->getUsername();
$this->module->casService->getAttribute('mail')
$this->module->casService->getAttribute('title')=='TEACHER';
//$auth->assign($casRole, $user->id);
}
public function actionLogout()
{
$this->module->casService->logout(Url::home(true));
// In case the logout fails (not authenticated)
return $this->redirect(Url::home(true));
}
}
I place to the controller file the line:
require_once(APPPATH . '/../vendor/autoload.php');
and I init with:
$phpCAS = new phpCAS;
phpCAS::client(CAS_VERSION_2_0, 'sso-test.sch.gr', 443, '', false);
I am trying to generate a PDF document from CodeIgniter: 4.0.3 using fpdf library. I have copied fpdf library in app/ThirdParty folder.
I have included library reference at the top of controller like this.
<?php namespace App\Controllers\Purchase;
namespace App\ThirdParty\fpdf;
use CodeIgniter\Controller;
use FPDF;
I have created a class in the controller to extend FPDF to include header and footers like this.
class PDF extends FPDF
{
function Header()
{
}
}
I generate the pdf like this.
$pdf = new PDF();
$pdf->AddPage();
When I run the application, I get this error.
Error
Class 'FPDF' not found
114 class PDF extends FPDF
How to fix this?
You should checkout whatever your namespace in fpdf lib is. It looks like you're a bit confused about them and the use word
Here's an example on how to load a lib which is under the app/ThirdParty folder :
Your FPDF main class named FPDF.php :
<?php
// the path you need to follow to access your file
namespace App\ThirdParty;
class FPDF {
public function __construct() {
// do your things
}
}
Your Controller named Foo.php :
<?php
namespace App\Controllers;
// the namespace of the lib file + its class name
use App\ThirdParty\FPDF;
class Foo extends \CodeIgniter\Controller {
public function myPDF() {
$pdf = new FPDF();
}
}
First include font folder, fpdf.php file and fpdf.css file in the ThirdParty folder.
Open fpdf.php file and include following 2 lines after <?php
namespace App\ThirdParty;
use Exception;
Then rename the fpdf.php file in ThirdParty folder to FPDF.php
Now you can import fpdf using:
use App\ThirdParty\FPDF;
I can't use binance api in laravel
I installed Php binance api from composer require "jaggedsoft/php-binance-api #dev" but examples not working in laravel.I had some errors when I tried.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
require '../vendor/autoload.php';
class BinanceController extends Controller
{
public function list()
{
$api = new Binance\API();
$key = "----";
$secret = "---";
$api = new Binance\API($key, $secret);
$price = $api->price("BNBBTC");
return $price;
}
}
When I runned the route I got this error:
Symfony\Component\Debug\Exception\FatalThrowableError Class
'App\Http\Controllers\Binance\API' not found
You're not importing Binance\API correctly. Laravel believes the Binance\Api class is located in the App\Http\Controllers\Binance namespace. Which it is not.
Try $api = new \Binance\API();
Or put it in your use cases.
use Binance\API
I also found an old wrapper which you may be able to import if there hasn't been any changes to Binance since but I highly doubt it. Since your case is specific to Laravel, look for a Binance wrapper for Laravel specifically. Here may contain some useful information on how to use non-laravel packages, with laravel
I have this error when i am trying to access a website from wamp, it is done in codeigniter.
Error:
localhost is currently unable to handle this request. HTTP ERROR 500
homeindex controller
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class HomeIndex extends CI_Controller {
public function __construct(){
parent:: __construct();
$this->load->helper('html');
$this->load->helper('form','url','file');
$this->load->library('session','upload');
}
public function index()
{
//$this->load->view('coming_soon');
$this->load->view('homeIndex');
}
}
route
$route['default_controller'] = 'HomeIndex';
$route['404_override'] = '';
$route['translate_uri_dashes'] = FALSE;
I am able to access other website which are not done using any frameworks.
This website is done using codeigniter. I am not able to access the website.
Can anyone tell me what is the problem?
Multiple loads with one call are done using an array:
$this->load->helper(array('form','url','file'));
$this->load->library(array('session','upload'));
https://www.codeigniter.com/user_guide/libraries/loader.html#CI_Loader::helper
if that doesn't work turn on error reporting (switch to development mode in index.php) and see what the actual error is. 500 error can be many things...
always display an error message on my browser:
An Error Was Encountered
Non-existent class: IOFactory
all classes PHPExcel, i extract on library.
Here it is my controller code
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Report extends CI_Controller
{
public function __construct()
{
parent::__construct();
$this->load->helper(array('form','url'));
}
public function index()
{
$this->load->library('phpexcel');
$this->load->library('PHPExcel/IOFactory.php');
$objPHPexcel = PHPExcel_IOFactory::load('tandaterima.xlsx');
$objWorksheet = $objPHPexcel->getActiveSheet();
//Daftar barang (4item)
$objWorksheet->getCell('B16')->setValue('UTP');
$objWorksheet->getCell('B17')->setValue('Cross');
$objWorksheet->getCell('B18')->setValue('');
$objWorksheet->getCell('B19')->setValue('');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'Excel5');
$objWriter->save('write5.xls');
}
}
please help me.
Follow the instruction here
https://github.com/EllisLab/CodeIgniter/wiki/PHPExcel
Please remember to remove the PHPExcel_ part in the class name in IOFactory.php. And change the construct function from private to public
ensure that u save PHPExcel/IOFactory.php inside libraries folder and load it as $this->load->library('PHPExcel/iofactory');
You can replace this line
$objWriter = PHPExcel_IOFactory::createWriter($objPHPexcel, 'Excel5');
by this line
IOFactory::createWriter($objPHPexcel, 'Excel5');
First you need to place your PHPExcel folder inside thirdparty folder. Then create class file in the library folder. There you need to include thirdparty/PHPExcel file folder and extend the class. After that you can use it in your controller.
And in some Linux Server, you have to care about case.
$this->load->library('PHPExcel');
$this->load->library('PHPExcel/IOFactory');
Codeiginiter 3 supports Composer to use PHPExcel:
In application/config/config.php, set $config['composer_autoload'] to TRUE.
Then you can use Composer to install PHPExcel in Codeiginiter :
composer require phpoffice/phpexcel
Further, You could try PHPExcel Helper to easier handle PHPExcel:
composer require yidas/phpexcel-helper
https://github.com/yidas/phpexcel-helper