Welcome Guest, Not a member yet? Register   Sign In
Using a helper function in the View file
#1

[eluser]ridley1012[/eluser]
Hi, from my understanding it is bad practice to use a helper function within the view file. The problem I have is i'm not sure how to separate it and use it in the controller instead. I currently have a date stored as a timestamp in the db, I have the following controller retrieving the data from the db:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Vehicles extends MY_Controller {

private $page = "vehicles";

  public function index()
{  
  $this->load->helper('multi_function');
  $this->load->model('vehicle_model', 'vehicles', TRUE);
  $data['page'] = $this->page;
  $data['title'] = "Administration Panel - Vehicle List";
  $data['vehicles'] = $this->vehicles->get_all_vehicles();
  $this->load->view('templates/admin/header', $data);
  $this->load->view('templates/admin/sidebar');
  $this->load->view('admin/vehicles');
  $this->load->view('templates/admin/footer');
}
}
?>

using this model file:
Code:
<?php
class Vehicle_model extends CI_Model {

    function __construct()
    {
        // Call the Model constructor
        parent::__construct();
    }
    
function get_all_vehicles()
{
  $this->db->order_by('registration ASC');
  $query = $this->db->get_where('vehicles', array('sold' => 'No'));
  return $query->result();
}
}
?>

as you can see it returns the data as an array and I use a foreach loop inside the view to display the data in a table. I would like to convert the timestamp to a date which I am currently doing using a function I have created in a custom helper but this function is been used within the view file. any suggestions on how to use the function inside the controller instead?

would I have to pull the array apart inside the controller, do the amendments and then rebuild the array?

thanks


Messages In This Thread
Using a helper function in the View file - by El Forum - 04-26-2012, 08:01 AM
Using a helper function in the View file - by El Forum - 04-26-2012, 09:44 AM
Using a helper function in the View file - by El Forum - 04-26-2012, 09:54 AM
Using a helper function in the View file - by El Forum - 04-26-2012, 09:56 AM
Using a helper function in the View file - by El Forum - 04-26-2012, 10:14 AM
Using a helper function in the View file - by El Forum - 04-26-2012, 10:18 AM
Using a helper function in the View file - by El Forum - 04-26-2012, 10:27 AM
Using a helper function in the View file - by El Forum - 04-26-2012, 10:49 AM
Using a helper function in the View file - by El Forum - 04-26-2012, 11:15 AM
Using a helper function in the View file - by El Forum - 04-26-2012, 12:18 PM
Using a helper function in the View file - by El Forum - 04-26-2012, 12:29 PM
Using a helper function in the View file - by El Forum - 04-26-2012, 02:10 PM



Theme © iAndrew 2016 - Forum software by © MyBB