allrested wrote
Hello, i want to integrate Mpdf library into tastyigniter but I dont know the proper way to add library into tastyigniter. Is method on attachments correct one? Thanks for ur attention :)
No, thank you for your time.
The way you've tried is correct and will probably work, however i'd rather have everything inside one folder. This way, you will be able to add more functions later to make it a module for TI with backend options.
Create a folder inside "extensions" folder and name it "generate_pdf".
Inside the "generate_pdf" folder, create libraries folder.
Inside the libraries folder copy and paste the M_pdf.php file and the MPDF folder
**You might lose the changes in the Orders.php file when you upgrade, so you'll want to make less changes to the core files until theres a better way to keep those changes after upgrade.
You can try by adding more function to the extension:
You'll need to create a config/generate_pdf.php file in your extension folder, so copy one from any of the existing extension and edit accordingly.
Create a new controller file inside generate_pdf/controllers/Admin_generate_pdf.php, file name must match Admin_{folder name}
Then, extract the generate() method into its own class (controller) by extending the Admin_Controller
The file content should look like
<?php if ( ! defined('BASEPATH')) exit('No direct access allowed');
// you wont have to require if you will only use the controller within the Admin Context
require_once IGNITEPATH.'core/Admin_Controller.php';
class Admin_generate_pdf extends Admin_Controller {
public function generate() {
// your code here
// $this->load->library('m_pdf');
// $this->m_pdf->load($file);
// after your code execution its best to redirect back to the referrer page,
// if you are not using a view or returning any data.
}
}
Now 99% of your changes are safe and you have everything in the generate_pdf folder, you can even access your extension from site.com/generate_pdf/admin_generate_pdf (only admin can access).
The last step is adding a button to Orders page, you can accomplish within a theme file instead of controller. Copy and paste the code below anywhere
<a href="<?php echo root_url('generate_pdf/admin_generate_pdf/generate'); ?>">PDF</a>
within line 111 and 118 in the tastyigniter-blue/orders_edit.php file.
You can always follow your approach but the idea is to make less changes to core files. Let me know if anything isn't clear :)