Welcome Guest, Not a member yet? Register   Sign In
Data transfer between controller functions
#21

[eluser]n0xie[/eluser]
[quote author="Mareshal" date="1245617565"]I tried n0xie's suggestion.

I only try to use the data from another function in same controller, and that was only a simple example.[/quote]
Sorry my bad...

My example was a little bit wrong.
Change the last function call to $this->index():
Code:
function subscribe(){
        
        //you should sanitize here!!!!
        //let's use filter for now
        
        if (filter_var($this->input->post('email'), FILTER_VALIDATE_EMAIL))
        {            
          $this->newsletter->add($this->input->post('email'));  
          $this->data['subscription'] = TRUE;
        }
        else
        {
          $this->data['subscription'] = FALSE;
        }
      $this->index();
    }
#22

[eluser]Mareshal[/eluser]
aaaa, so index uses function renderpage like a third party, and all data from other function inside same controller are passed trought index function. I think I understand now.

But how to call another function from another controller? is this possible?
#23

[eluser]n0xie[/eluser]
[quote author="Mareshal" date="1245682915"]
But how to call another function from another controller? is this possible?[/quote]
The short answer is 'no'. The long answer is 'yes'. The way CI normally works it's not possible but you can change this behaviour (like most behaviour) to your liking. There are several good posts about how to approach this, so I recommend you check out the search function.
#24

[eluser]Mareshal[/eluser]
Ok, I know aobut search function, but the problem is what to search?

edit: I think this is the answer -> http://ellislab.com/forums/viewthread/119273/

"Extending controller classes is more appropriate than creating libraries. "

I can't test it now, but is this the answer?
#25

[eluser]n0xie[/eluser]
Well this isn't Python. There isn't 1 right way to do things: there are many ways to achieve what you want. It's up to you to decide how you want to do it Smile
#26

[eluser]wiredesignz[/eluser]
Ignore the cryptic bullshit.

Yes, Extending controller classes is more appropriate than creating libraries in most circumstances and you can call a controller method from another controller by using the HMVC extensions.

See my signature below.
#27

[eluser]n0xie[/eluser]
[quote author="wiredesignz" date="1245700414"]Ignore the cryptic bullshit.
[/quote]
What exactly is cryptic about my replies?
#28

[eluser]wiredesignz[/eluser]
Quote:The short answer is 'no'. The long answer is 'yes'.


...and WTF has Python got to do with CI or the OP's question?
#29

[eluser]n0xie[/eluser]
[quote author="wiredesignz" date="1245701413"]WTF has Python to do with CI?[/quote]
Can you read??

Quote:Well this isn’t Python. There isn’t 1 right way to do things
Quote:Zen of Python :
There should be one-- and preferably only one --obvious way to do it.
#30

[eluser]TheFuzzy0ne[/eluser]
wiredesigns is just like a Slinky - Not really good for anything but you can't help but smile when you push him down the stairs. Smile




Theme © iAndrew 2016 - Forum software by © MyBB