I am using CodeIgniter on a project that Generates PDF. it work once in single PDF now I tried another it got an error. Here is the code:
class Checkout extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->model('PurchaserModel', 'purchaser');
....
$this->load->library('M_pdf');
}
public function save(){
.....
$data['orders'] = $this->order->get_order_details($logged_in_id);
if($data['orders']){
$details = $this->purchaser->get_purchaser_details($this->session->userdata['logged_in']['username']);
$data['details'] = convertvalue($details);
$order_id = $data['orders'][0]['order_id'];
$data['order_id'] = $order_id;
}
// 1st PDF work fine if the other generate PDF is commented out
$purchaser_sheet_html = $this->load->view('pdf/purchaser_sheet', $data, true);
$purchaser_sheet_html2 = $this->load->view('pdf/purchaser_sheet_page_2', $data, true);
$pdf1 = $this->m_pdf->load();
$pdfFilePath1 = uniqid(rand(), true);
$pdfFilePath = "purchase-order-summary-".date('Ymdhis')."-".$pdfFilePath1.".pdf";
$pdf1->WriteHTML($purchaser_sheet_html);
$pdf1->AddPage();
$pdf1->WriteHTML($purchaser_sheet_html2);
$pdf1->Output("./uploads/".$pdfFilePath, "F"); // this is line 425 and got error
// 2nd PDF when this code is up, it got an error
$construction_sheet_summary = $this->load->view('pdf/construction_sheet_summary', $data, true);
$pdf2 = $this->m_pdf->load();
$pdfFilePath2 = uniqid(rand(), true);
$pdfFilePath_2 = "construction-sheet-summary-".date('Ymdhis')."-".$pdfFilePath2.".pdf";
$pdf2->WriteHTML($construction_sheet_summary); // this is line 433 and got error
$pdf2->Output("./uploads/".$pdfFilePath_2, "F");
$this->db->update($this->db->dbprefix('order'), array('purchaser_sheet' => $pdfFilePath, 'construction_sheet' => $pdfFilePath_2), array('ID' => $insert_id));
$email_settings = $this->settings->email_settings();
}
and this is the complete error message:
A PHP Error was encountered
Severity: Warning
Message: count(): Parameter must be an array or an object that implements Countable
Filename: mpdf/mpdf.php
Line Number: 1770
Backtrace:
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 1770
Function: _error_handler
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 7591
Function: Close
File: C:\xampp1\htdocs\dev.app.com\public\application\controllers\Checkout.php
Line: 425
Function: Output
File: C:\xampp1\htdocs\dev.app.com\public\index.php
Line: 315
Function: require_once
A PHP Error was encountered
Severity: 8192
Message: The each() function is deprecated. This message will be suppressed on further calls
Filename: mpdf/mpdf.php
Line Number: 9143
Backtrace:
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 9143
Function: each
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 27927
Function: _putimages
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 9508
Function: _putresources
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 1797
Function: _enddoc
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 7591
Function: Close
File: C:\xampp1\htdocs\dev.app.com\public\application\controllers\Checkout.php
Line: 425
Function: Output
File: C:\xampp1\htdocs\dev.app.com\public\index.php
Line: 315
Function: require_once
An uncaught Exception was encountered
Type: Error
Message: Class 'MpdfException' not found
Filename: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line Number: 32456
Backtrace:
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 22328
Function: ConvertSize
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 15440
Function: setCSS
File: C:\xampp1\htdocs\dev.app.com\public\application\third_party\mpdf\mpdf.php
Line: 13614
Function: OpenTag
File: C:\xampp1\htdocs\dev.app.com\public\application\controllers\Checkout.php
Line: 433
Function: WriteHTML
File: C:\xampp1\htdocs\dev.app.com\public\index.php
Line: 315
Function: require_once
I tried to debug the code and I found out this line got an isseu
$construction_sheet_summary = $this->load->view('pdf/construction_sheet_summary', $data, true);
I construction_sheet_summary.php is present, I tried to remove all php code on that file but got the same error.
do anyone have an idea about my case?
As #Viney recommends in the comment, upgrade to the (preferably) last version of mPDF using composer - this will solve both dependencies and the each() deprecation warning.
Related
Here is my controller function code:
public function dispcp(){
$data = array(
'company' => $this->input->post("company"),
'fyfrom' => $this->input->post("fyfrom"),
'fyto' => $this->input->post("fyto"),
);
$this->load->view('view',$data);
}
Here the data comes from a form from another view.
this is what my code in view.php looks like :
<?php print_r ($data[0]->fyfrom); ?>
Error:Message: Undefined variable: data
Filename: views/view.php
Line Number: 14
Backtrace:
File: C:\wamp\www\admin\application\views\view.php
Line: 14
Function: _error_handler
File: C:\wamp\www\admin\application\controllers\Dashboard.php
Line: 586
Function: view
File: C:\wamp\www\admin\index.php
Line: 263
Function: require_once
Works correctly in Controller, not in view.
Once the data is passed to the view you need to use the array keys are variables directly :
<?php print_r($fyfrom); ?>
A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: models/Email_model.php
Line Number: 187
Backtrace:
File: /public_html/application/models/Email_model.php Line: 187
Function: _error_handler
File: public_html/application/controllers/Home.php Line: 1409
Function: send_code_sms
File: /public_html/index.php Line: 292 Function: require_once
Controller:
if ($this->input->post('password1') == $this->input->post('password2')) {
$password = $this->input->post('password1');
$data['password'] = sha1($password);
$this->db->insert('vendor', $data);
$this->email_model->account_opening('vendor', $data['email'], $password);
$id = $this->db->insert_id();
*$this->email_model->send_code_sms('vendor', $id);*
echo 'done';
}
Model:
//email_verify
function send_code_sms($type,$id){
$code = $this->db->get_where($type,array($type.'_id' => $para2))->row()->sms_code;
*$phone = $this->db->get_where($type,array($type.'_id' => $para2))->row()->phone;*
$text = translate('your_verification_code_is')." : ".$code;
$this->do_sms($phone,$text);
}
View:
require_once BASEPATH.'core/CodeIgniter.php';
I am having this error on my site. I Sent an email to my developer to fix the errors causing my customers to be unable to register accounts but I have not received any replies in 5 days. The sms verification feature is not supposed to used yet because of no api. So the only thing supposed to be working is email verification. Whenever someone tries to register, the error above appears.
Need Help. Thanks
(There is an asterisk to indicate the line with the error)
It seems that I just can't pass an array in another function into main view.
My index() function is =>
public function index()
{
$this->load->view('anasayfa');
}
My aforementioned function is =>
public function pozisyon_tutma()
{...
....
print_r(array_values($pozisyon));
$GLOBALS['pozisyong'] = $pozisyon;
}
which works...
I am seeking something like =>
public function index()
{
$this->pozisyon_tutma();
$data['hoppa']=$GLOBALS['pozisyong'];
$this->load->view('anasayfa', $data);
}
and I am seeking in view 'anasayfa' (which is the main view) something like this code to work=>
<?php
print_r(array_values($hoppa));
?>
However this code gives the following error=>
A PHP Error was encountered
Severity: Notice
Message: Undefined variable: hoppa
Filename: views/anasayfa.php
Line Number: 19
Backtrace:
File: D:\wamp\www\proje\application\views\anasayfa.php
Line: 19
Function: _error_handler
File: D:\wamp\www\proje\application\controllers\Welcome.php
Line: 24
Function: view
File: D:\wamp\www\proje\index.php
Line: 292
Function: require_once
A PHP Error was encountered
Severity: Warning
Message: array_values() expects parameter 1 to be array, null given
Filename: views/anasayfa.php
Line Number: 19
Backtrace:
File: D:\wamp\www\proje\application\views\anasayfa.php
Line: 19
Function: array_values
File: D:\wamp\www\proje\application\controllers\Welcome.php
Line: 24
Function: view
File: D:\wamp\www\proje\index.php
Line: 292
Function: require_once
All help will be much appreciated. I checked all other threads in stackoverflaw and could not make any of them work in my case... Thank you all
You should use in your controller:
$data = array('key1'=>$value1, 'key2'=>$value2, 'key3'=>functionX()....);
$this->load->view('yourview.php',$data);
And in the view to access to the array of values:
echo $key1; // prints $value1.
echo $key2; // prints $value2.
Also, you could use $_SESSION to store some variables in CI. Hope it helps.
I did it in the following way=>
public function index()
{
require('Hesaplama.php');
$Hesaplama = new Hesaplama();
$data['hoppa']=$Hesaplama->pozisyon_tutma();
$this->load->view('anasayfa', $data);
}
It works. I returned $pozisyon which is an array as #mic suggested. I will keep the suggestions of #JP. Aulet in case I need them in the near future. Thank you all...
Error
A PHP Error was encountered
Severity: Warning
Message: preg_match() expects parameter 2 to be string, object given
Filename: libraries/mpdf.php
Line Number: 22307
Backtrace:
File: D:\xamp\htdocs\ci_test\application\libraries\mpdf.php
Line: 22307
Function: preg_match
File: D:\xamp\htdocs\ci_test\application\libraries\mpdf.php
Line: 13118
Function: ReadCharset
File: D:\xamp\htdocs\ci_test\application\controllers\Welcome.php
Line: 28
Function: WriteHTML
File: D:\xamp\htdocs\ci_test\index.php
Line: 292
Function: require_once
this is my controller
$this->load->library('mpdf');
$html = $this->load->view('welcome_message');
$this->mpdf->WriteHTML($html);
$this->mpdf->Output();
Try loading view likr this,
$html = $this->load->view('welcome_message','',TRUE);
^ will get the value to variable.
Im working on my first project in CodeIgniter and I wonder How can I use my class from library in my Controller.
libraries/Twitterclass.php:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Twetterclass {
public function __construct($hashtag, $tweet_id)
{
require_once('TwitterAPIExchange.php');
//There is my working code
//I want to make use of this $n in my Controller
return $n;
}
}
/* End of file Twetterclass.php */
My Controller:
public function microtweets()
{
$params = array('hashtag' => 'somehashtag', 'tweet_id' => '673899616799191040');
$data['count_tweets'] = $this->load->library('Twetterclass', $params);
$this->load->view('tweets', $data);
}
I want to use his extended class in my controller and work there on this $n value or for example display it in my View.
I get few errors:
A PHP Error was encountered
Severity: Warning
Message: Missing argument 2 for Twetterclass::__construct(), called in
/home/jail/kg7dad5/home/kg7dad5/domains/badzlepszy.pl/public_html/coinmonitor/system/core/Loader.php
on line 1246 and defined
Filename: libraries/Twetterclass.php
Line Number: 5
Backtrace:
File: /application/libraries/Twetterclass.php Line: 5 Function:
_error_handler
File: /application/controllers/Cointweet.php Line: 24 Function:
library
File: /public_html/coinmonitor/index.php Line: 292 Function:
require_once
first try to debug parameter you passed in constructor
public function __construct($hashtag, $tweet_id)
{
echo $hashtag;
echo $tweet_id;
die;
}
according to your code, change like this,
public function __construct($arr)
{
echo $arr['hashtag'];
echo $arr['tweet_id'];
exit;
}
Because you are passing 1 array, so access in library with array index.