Welcome Guest, Not a member yet? Register   Sign In
New to CI not sure on helpers
#1

[eluser]Unknown[/eluser]
Hello,

I am new to code igniter but have learn the basics of the how display load web pages etc.

currently working on a team project and we've got a form that we want people to fill in which at one point asks them their occupation and industry they are in. What i have asked to do is to make a helper which when integrated with the other peoples code will allow the form when clicking on dropdown or text box with automatically have the industries, once clicked on that one the next box will have the occupations tied to that industry.

The data is on a mysql table so it needs to be pulled from there.

i only know the basics of making web pages and loading them and some basic mysql query syntax, if this were regular php i could maybe do this but they want it done in a way that a helper is written and can be implemented.

i am not too sure about to even start but ive managed to extract the layout of a helper , theyve already written a model and controller for it.

Code:
<?php

if (!defined('BASEPATH'))
exit('No direct script access allowed');

if (!function_exists('get_industry')) {
function get_industry($industry) {
  
  // function code to go here
  
}
}

if (!function_exists('get_occupation')) {
function get_occupation($occupation) {
  
  // function code to go here
  
}
}

if (!function_exists('get_hmrc')) {
function get_hmrc($hmrc) {
  
  // function code to go here
  
}
}

any help is appreciated and i am very sorry for my lack of knowledge
#2

[eluser]InsiteFX[/eluser]
To access anything in CI from a helper, you need to do this

Code:
$_ci = get_instance();

// EXAMPLE:

// ------------------------------------------------------------------------

/**
* Helper asset_url()
*
* @access public
* @param string
* @return string
*/
if ( ! function_exists('asset'))
{
function asset($uri)
{
  $_ci = get_instance();

  return $_ci->config->base_url('assets/'.$uri);
}
}
#3

[eluser]LuckyFella73[/eluser]
Quote:What i have asked to do is to make a helper which when integrated with the other peoples code will allow the form when clicking on dropdown or text box with automatically have the industries, once clicked on that one the next box will have the occupations tied to that industry.

The data is on a mysql table so it needs to be pulled from there.

If it's that you are trying to solve then helpers are not what you are looking for.
Helpers are basically just PHP functions you reuse in your PHP code and you have no direct
acccess to them from your frontend part.

To achieve what you described you would have to do ajax calls after each dropddown-select or
provide one JSON object having all nessessary well structured data on page load and handle the dropdown data via javascript without ajax calls.




Theme © iAndrew 2016 - Forum software by © MyBB