I have to make some design decision in my application using Codeigniter.
I have a method in controller that calls a library for creating PDF. Also I have some class that takes a number as an argument and returns string (number verbally ).
I would like to know what is the bestr practice to pass data between all this class. Is this a task of controller to call all libraries (between step2 and step 3) and provide all prepared data to a model that will create PDF. Or is this a task of Model itself to transform provided raw data by loading and calling class that converts number to string.
What would be the best solution in terms of loose coupling and modularity and clarity of the code.
This is a controller:
class Payu extends CI_Controller
{
public function raport($task_id)
{
/* (step 1) Load necessarty models */
$this->load->model('MTasks');
$this->load->model('mpdfinvoice');
/* (step 2) task details from DB */
$task_details = $this->MTasks->getTaskDetails($task_id);
/* (step 3) create PDF that will be send */
$this->mpdfinvoice->pdf($task_details);
/* (step 4) compose an email with attached pdf */
$this->email->from($this->config->item('noreply_email'));
$this->email->to($task_details['email']);
$this->email->attach('invoiceJustCreated.pdf');
$this->email->subject('opłaciłes to zlecenie');
$message = 'some message goes here';
$this->email->message($message);
$this->email->send();
}
}
This is a model that creates PDF file (called by controller)
class mpdfinvoice extends CI_Model
{
public function pdf($task_details)
{
/* (step 1) load necesary library and helper */
$this->load->library(array('fpdf' ));
$this->load->helper('file');
/* (step 2) set PDF page configuration*/
$this->fpdf->AddPage();
$this->fpdf->AddFont('arialpl','','arialpl.php');
$this->fpdf->SetFont('arialpl','',16);
/* (step 3) show data on PDF page */
$this->fpdf->cell('','',$task_details['payment_amount'] ,1);
/* I want to have "payment amount" verbally here
So Should I load and call the convert class here or
should I have this data already prepared by the controller
and only output it ? */
}
}