Welcome Guest, Not a member yet? Register   Sign In
Can't access post->input() from autoloaded Config files
#1

[eluser]heat23[/eluser]
My site has many pages and forms so I wanted to globalize some of the shared forum input attributes. For example.. I would want to put the following array declaration in some helper/config file so that I can access it from a view like: form_input($username_input)
Code:
$username_input = array(
              'name'        => 'username',
              'id'          => 'username',
              'value'       => (($this->CI->input->post('save')) ? $this->CI->input->post('username') : $row->city),
              'maxlength'   => '100',
              'size'        => '50',
              'style'       => 'width:50%',
            );

I tried creating a custom config file and placing it in the /config dir and included the line $this->CI =& get_instance(); at the top, however, if the form has an error, it is not setting the POST value.

Does anyone know how to either
1) Fix this above scenario so I can access input->post() from a config file
2) Suggest a better method for globalizing form attributes
#2

[eluser]Colin Williams[/eluser]
Everybody sing it with me: "MY_Controller, MY_Controller. Anything is possible with MY_Controller..." That's as far as I've gotten with the song.
#3

[eluser]heat23[/eluser]
Can you please be more specific on how I would set something like this up using MY_Controller?
#4

[eluser]Kamape[/eluser]
Are you sure you can use instance-dependant variables in config files? ($this->CI).

Why not just use $CI =& get_instance();

Else you can always var_dump($this->CI->input) or something like that to find out whether you have an instance.
#5

[eluser]Kamape[/eluser]
MY_Controller is to extend the usual Controller class in your library folder with a user-created class called MY_Controller which lays in the file MY_Controller.php.

Example:

class MY_Controller extends Controller
{
//Do som fluffy code-work with you global-form-specific-code here
}
#6

[eluser]Dam1an[/eluser]
[quote author="Colin Williams" date="1246926120"]Everybody sing it with me: "MY_Controller, MY_Controller. Anything is possible with MY_Controller..." That's as far as I've gotten with the song.[/quote]

Haha! What melody is that supposed to be? Cause I can't seem to get it right
We could make a whole song, where each line is a solution to a problem, make it a community effort where everyone adds a line
#7

[eluser]Kamape[/eluser]
[quote author="Dam1an" date="1246926788"][quote author="Colin Williams" date="1246926120"]Everybody sing it with me: "MY_Controller, MY_Controller. Anything is possible with MY_Controller..." That's as far as I've gotten with the song.[/quote]

Haha! What melody is that supposed to be? Cause I can't seem to get it right
We could make a whole song, where each line is a solution to a problem, make it a community effort where everyone adds a line[/quote]

Just picked up the guitar, trying to get some nice chords to fit in. :-)
#8

[eluser]heat23[/eluser]
How do I progammatically call the array in MY_Controller that contains the attributes for the form field
#9

[eluser]Kamape[/eluser]
Everything in MY_Controller is accessible in your Controllers 'cause overriding a framework class is practically extending that class.

Read more here:

http://ellislab.com/codeigniter/user-gui...aries.html
#10

[eluser]Colin Williams[/eluser]
Quote:Haha! What melody is that supposed to be? Cause I can’t seem to get it right

I'm thinking sort of showtunes-y, with big band backing it up. Or maybe we could adapt "My Sharona"

Quote:Just picked up the guitar, trying to get some nice chords to fit in.

Ha! Awesome.

But back to our regularly scheduled programming (see what I did there?) Here's some code for ya:

Code:
class MY_Controller extends Controller {

  function MY_Controller()
  {
    parent::Controller();
    // Do what you need to here, then make any data available to child controller classes
    // by setting a property "$this->var = $value" or make any data available to views
    // by using $this->load->vars()
  }

}




Theme © iAndrew 2016 - Forum software by © MyBB