Welcome Guest, Not a member yet? Register   Sign In
Changing from a Library to Controller
#1

[eluser]Fielder[/eluser]
I really don't understand the difference between Controllers and Libraries, other than I've created libraries to house functions that are used throughout the entire application and are called from within various other controllers.
Hence, in my controllers I'll load libraries
Code:
class Business_Form extends Controller
{
    function Business_Form()
    {
        
        parent::Controller();
        
        $this->load->library('DX_Auth');
        $this->load->library('RTUI_App');
...
        
    }

and then call the functions in the library as needed...
Code:
$this->rtui_app->revision_entry('business', $action, $bus_number);

So my question is in the controller below (ContractStore_Form).. can i change all the $this->data[''] to just $data['']? If I do just that, will I have problems in the _load_xajax getting my $data['xajax_js'] into my view?

Can I move all the lines in _load_xajax directly into the index() function eliminating _load_xajax?

Code:
class ContractStore_Form extends Controller
{
    var $data;

    function ContractStore_Form()
    {
        
        parent::Controller();

        $this->load->library('DX_Auth');
        $this->load->library('RTUI_App');
        
        $this->load->model('Stores', 'store', true);
        
    }

    function index()
    {
        
        $this->_load_xajax();
        
        // Store Names
        $this->data['storename_name_dropdownlist'] = $this->build_storename_name_dropdownlist('0');
        
        // Store Numbers
        $this->data['div_store_number'] = "<select id='store_number' name='store_number' size='8' style='width:200px;' />";
        
        // Store UPS Codes
        $this->data['div_store_upscode'] = "<select id='store_upscode' name='store_upscode' size='8' style='width:200px;' />";

        // result
        $this->data['txt_result'] = "";

        // load misc data
        // $this->_load_misc_data();

        // load views
        // $this->_load_views();
        
        // $this->load->view('site_layout', $this->data);
        
        $this->data['title'] = "RTUI Contract - Stores";
        $this->data['content_header_id'] = "generic_form_add";
        $this->data['content_header_title'] = "Customer Form Entry";
        $this->data['session_employee_name'] = $this->rtui_app->get_loggedIn_user($this->session->userdata('employee_id'));
                
        $this->load->view('include/header', $this->data);  
        $this->load->view('contract_store_add');
        $this->load->view('include/footer');
        
    }

    function _load_xajax()
    {
        
        $this->load->library('xajax_core/Xajax');
        
        $this->xajax->registerFunction(array('storename_name_onchange', &$this, 'storename_name_onchange'));
        
        
        $this->xajax->registerFunction(array('store_number_onchange', &$this, 'store_number_onchange'));
        
        
        $this->xajax->registerFunction(array('store_upscode_onchange', &$this, 'store_upscode_onchange'));
        
        $this->xajax->processRequest();
        
        $this->data['xajax_js'] = $this->xajax->getJavascript(base_url().'assets/js');
        
    }

I don't believe this particular file classifies as a Library because I won't be calling it's functions from other controllers. So I wanted to convert it to a regular controller and put it in my application/controller folder.
Hope this makes sense.
#2

[eluser]Evil Wizard[/eluser]
You can change $this->data to $data or whatever in your controller as you are explicitly passing in the variables to the view with $this->load->view('include/header', $this->data);




Theme © iAndrew 2016 - Forum software by © MyBB