martin.giesler Posted February 18, 2015 Posted February 18, 2015 Hello,how can i integrate jrs-rest-php-client in the php framework codeigniter?I want to use it as a Helper Class in codeigniter.
ferm Posted August 14, 2023 Posted August 14, 2023 Posible solución https://blog.linuxitos.com/post/codeigniter-3-jaspersoft-rest-clientEn el archivo descargado de codeigniter instalar desde composercomposer require jaspersoft/rest-client[/code]Una vez instalado crear un archivo helper con la función de reporte de la siguiente manera:<?phprequire_once "vendor/autoload.php";use JaspersoftClientClient; function reporte($idRegistro, $name, $params, $type = 'pdf'){ $ci = &get_instance(); try { $client = new Client('http://localhost:8080/jasperserver', 'jasperadmin', 'jasperadmin'); $report = $client->reportService()->runReport('/reports/'.$name, $type, null, null, $params); $nombre_temporal = str_replace('/', '_', $name).'_'.$idRegistro.'.'.$type; $config['upload_path'] = './files/reports/'; /* $config['max_size'] = '1000000'; $config['max_width'] = '10240000000'; $config['max_height'] = '76889'; $config['encrypt_name'] = true; $config['allowed_types'] = 'jpg|jpeg|png|gif|pdf'; $config['file_name'] = $nombre_temporal; */ write_file($config['upload_path'].$nombre_temporal, $report); return 'files/reports/'.$nombre_temporal; } catch (Throwable $error) { return 'error '.$error; }}[/code]Para usarlo desde el controaldor sería de la siguiente manera:<?phpdefined('BASEPATH') OR exit('No direct script access allowed');class JasperReport extends CI_Controller { public function __construct(){ parent::__construct(); $this->load->helper('reports'); $this->load->library('session'); } public function index() { $params = [ 'nombre_movimiento' => 'Reporte uno', 'autoriza' => '', 'cargo' => '', ]; $data['pdf'] = reporte(1, 'Codeigniter/reporteuno', $params, 'pdf'); $this->load->view('report', $data); }}[/code]En la vista sería de éste modo:[...] <div class="row"> <div class="col-md-12 mt-4"> <h2>Test jasper reports</h2> <p> PDF: <a href="<?=base_url($pdf);?>" target="_blank"><?=base_url($pdf);?></a> </p> </div> </div> <div class="row"> <div class="col-md-12"> <embed src="<?=base_url($pdf);?>" type="application/pdf" width="100%" height="600px"/> </div> </div>[...][/code]Ajustar los enlaces o configuraciones de acuerdo a su proyecto.
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now