Codeigniter insert dữ liệu copy từ file word
Codeginiter
Giải xử bạn có một trường (field) cho phép người dùng upload nội dung copy từ file word…thường một số định dạng copy từ word, lưu vào CSDL MySQL sẽ bị lỗi font tiếng việt.
Lúc này bạn gọi lớp text helper của Codeigniter để tránh trường hợp trên.
// Controller
$product_description = $this->input->post(‘product_description’);
// Trước khi insert field product_descript các bạn hạy gọi hàm sau để tránh trường hợp bị bể font tiếng việt
$this->load->helper(‘text’);
$product_description = ascii_to_entities($product_description);
Xem thêm thông tin tại đây: http://codeigniter.com/user_guide/helpers/text_helper.html
PHP Developer
nhantam
Codeigniter get last insert_id
Codeigniter lấy giá trị last insert_id
Ví dụ: Một trường hợp lấy giá trị insert_id bị lỗi
$this->db->insert($this->_table, $params);
//get last inserted $inserId = -1;
$inserId = $this->db->insert_id();
//insertId có giá trị khi:
– Table phải thiết kế primary key là Auto Increment
Ví dụ: CREATE TABLE `products` ( `prId` BIGINT(20) NOT NULL AUTO_INCREMENT, …vv)
//Ngược lại insertId sẽ không có giá trị:
– Nếu bạn thiết kế Primary key không ở chế độ Auto Increment
Codeigniter pdf libraries (php export pdf Unicode/UTF8 – Vietnamese)
Thêm mPDF libraries cho Codeigniter Framework, xuất file pdf Tiếng Việt có dấu (pdf Unicode/utf8)
Step 1: Download mPDF tại địa chỉ URL: http://www.mpdf1.com/mpdf/download
Step 2: Giải nén (uncompress) thư viện mPDF vào thư mục libraries của Codeigniter như sau:
your_project/system/application/libraries/mpdf/ (uncompress mpdf)
Step 3: Tạo file để gọi các lớp trong thư viện mpdf như sau:
Sau đó lưu (Save) tại đường dẫn sau:
your_project/system/application/libraries/Mpdf.php
Step 4: Sử dụng
$html = "Cho ví dụ minh họa"; $this->load->library('Mpdf'); $mpdf = new Pdf(); $mpdf->useAdobeCJK = true; $mpdf->SetAutoFont(AUTOFONT_ALL); $mpdf->WriteHTML($html); $save_file = $dir_bill.$filename.'.pdf'; $mpdf->Output(); //Neu xuat ra file $mpdf->Output('dir/ten_file_pdf', 'F');
nhantam
PHP Developer
Chuyên Thiết kế web bán hàng