Welcome Guest, Not a member yet? Register   Sign In
Questions about functions within controllers
#1

[eluser]yello[/eluser]
Hi!

I am having a bit of a problem figuring out how to code my new app. I was wondering if there is a way to kinda "redirect" the use of a particular function within the same controller. Let me explain:

Code:
<?
class Generator extends Controller
{
    function Generator()
    {
        error_reporting(0);
        parent::Controller();
        $this->load->model('functions');
        $this->load->model('other');
        $this->load->model('wp');
        $this->load->helper('string');
        $this->load->helper('url');
    }
    
    function index()
    {
        echo("generator");
    }
    
    function content()
    {
        if ($this->segment->uri(3) == 'some-string')
                {
                *redirect to some_string() function within the same controller*
                }
                else
                {
                *redirect another_thing() function*
                }
        }

        function some_string()
        {
               *do something*
        }

        function another_thing()
        {
               *do something else*
        }
}
}

Is that possible to do? I don't know where to put my app "logic".

I hope you guys can help me! (and understand what is my problem Tongue)

Thanks!
#2

[eluser]Tom Glover[/eluser]
As far as i no it should be like this:
Code:
<?
class Generator extends Controller
{
    function Generator()
    {
        error_reporting(0);
        parent::Controller();
        $this->load->model('functions');
        $this->load->model('other');
        $this->load->model('wp');
        $this->load->helper('string');
        $this->load->helper('url');
    }
    
    function index()
    {
        echo("generator");
    }
    
    function content()
    {
        if ($this->segment->uri(3) == 'some-string')
                {
                *redirect to some_string() function within the same controller*
                }
                else
                {
                *redirect another_thing() function*
                }
        }
     }
        //private function can only be called inside something else
        function _some_string()
        {
               *do something*
        }
        //try calling this by url and it wont work, but call it inside another function and it will.
        function _another_thing()
        {
               *do something else*
        }
}
#3

[eluser]wiredesignz[/eluser]
Code:
if ($this->segment->uri(3) == 'some-string')
{
    $this->some_string();
}
else
{
    $this->another_thing();
}
#4

[eluser]yello[/eluser]
Thank you guys!

both of your anwsers helped me alot!! Smile




Theme © iAndrew 2016 - Forum software by © MyBB