Asked  7 Months ago    Answers:  5   Viewed   75 times

What is the most simplist way to generate reports in Codeigniter framework? Is there any library available to do this task? Except charting what are the other resources to do this.



Found a nice solution myself. If you want to generate reports in csv format it is very easy with codeigniter. Your model function

function index(){
return $query = $this->db->get('my_table');
    Here you should note i am returning 
    the query object instead of 
    $query->result() or $query->result_array()

Now in controller

function get_report(){
    /* get the object   */
    $report = $this->my_model->index();
    /*  pass it to db utility function  */
    $new_report = $this->dbutil->csv_from_result($report);
    /*  Now use it to write file. write_file helper function will do it */
    /*  Done    */

No externals are required everything is available in codeigntier. Cheers! If you want to write xml file it is easy too.
Just use xml_from_result() method of dbutil and use write_file('xml_file.xml,$new_report) Visit these links they will help.

Database Utility Class


File Helper

Wednesday, March 31, 2021
answered 7 Months ago

You are using Firefox, aren't you?

You could try looking at system/libraries/Upload.php line 199:


Change that line to:

$this->_file_mime_type($_FILES[$field]); var_dump($this->file_type); die();

Then do upload your .wmv file. It would show something like application/octet-stream or whatever. Add that to your mimes.php. Hope this help =)

Similar answer here

Some links:

  • CodeIgniter forum's thread
  • Mimetype corruption in Firefox
  • Getting around IE’s MIME type mangling
Wednesday, March 31, 2021
answered 7 Months ago

you could create a new library in application/libriries and name the file MY_Form_validation

What you are doing here is extending the form_validation class so that you will not need to mess with the core files.

The MY_ is what is set on your config, be sure to check it if you changed yours.

sample MY_Form_validation.php

class MY_Form_validation Extends CI_Form_validation
   //this is mandatory for this class
   //do not forget this or it will not work
   public function __construct($rules = array(){
   public function method1($str){
     return $str == '' ? FALSE : TRUE;
   pulic function method2($str)
       //if you want a validation from database
       //you can load it here
       // or check the `form_validation` file on `system/libraries/form_validation`


  public function check_something_with_post($tr)
      return $this->CI->input->post('some_post') == FALSE ? FALSE : TRUE;

Basically, when you call a rule sample method1|method2 the value of your post field will be the parameter of the method. if you want to check other post you can do it by using $this->CI->input->post('name of the post');

when you want to pass a parameter just look at the form validation is_unique or unique code on system/libraries/form_validation you will have an idea.

To create a error message that goes with it go to application/language/english/MY_Form_validation_lang

Sample MY_form_validation_lang.php

$lang['method1'] = "error error error.";
$lang['method2'] = "this is an error message.";

if english does not exist on your application/language just create it.

check more atCreating libraries


On some linux or debian server you may want to change the file name from MY_Form_validation to MY_form_validation note the small f on the word form.

Wednesday, March 31, 2021
answered 7 Months ago

The problem from what I can see is that SSRS violates the Contract Centralisation Pattern. Instead your report should be generated from either the services you have created, or by extending those services. Otherwise you create a tight technology based coupling between your report and your databases, which will make it more difficult to modify, migrate or re-implement your travel and employee systems when the need arrises. The more reports you add this way, the more difficult it will become to change your Travel and Employee implementation.

If you haven't already, I would create reporting operations on the travel service, e.g., if you are using SOAP based services, add a GetTravelRequests operation, which accepts some sort of querying and pagination parameters, that just returns the TravelID, Travel Request Date, EmployeeID of the matching records. Then create a GetEmployeeTravelRequests, which composes GetTravelRequests with a GetEmployeeDetails operation from the Employee service.

This will be slower that an SSRS based report, but you are free to then change the underlying implementation of the Travel and Employee services, so long as you don't change the service contract.

I've kind-of assumed you are using SOAP, which is what the answer above is based upon, however if RESTful services are an option, then I would recommend the following. Instead of exposing numeric TravelIDs and EmployeeIDs, instead use URIs. For instance, the travel service will create a travel resource for the employee URI in the Travel database. Then create an Atom based feed of travel requests. You can either stop there and where the report user needs employee details, they can follow the employee URI link. Otherwise, you can use the employee URIs to create a composed Atom feed that includes the employee details for each travel request.

The main advantage of this latter approach is the reduced DB load through the use of HTTP Caching; HTTP GET is the most optimised operation in the world. Your report is now a live report, rather than only as current as when it was last generated, which may be once a day or once a month and if you structure your feed correctly, then the non-head pages never change and can be cached for a year or longer. If you assume that employee details change infrequently, then you can set the max-age to 1 day, in which case a query for a particular employees details will only hit the database once a day.

Finally, another nice benefit, is that it become trivially easy to add a TravelRequests collection resource to the Employee resource, which contains an Atom based paginated list of all the travel requests for that employee.

Friday, June 11, 2021
answered 5 Months ago

There is a question I ask myself when deciding this that I think will help you as well. The question is: Am I providing a feature to my framework or am I consolidating?

If you have a feature that you are adding to your framework, then you'll want to create a library for that. Form validation, for example, is a feature that you are adding to a framework. Even though you can do form validation without this library, you're creating a standard system for validation which is a feature.

However, there is also a form helper which helps you create the HTML of forms. The big difference from the form validation library is that the form helper isn't creating a new feature, its just a set of related functions that help you write the HTML of forms properly.

Hopefully this differentiation will help you as it has me.

Sunday, August 8, 2021
answered 3 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :