Welcome Guest, Not a member yet? Register   Sign In
beginner - data from view to controller
#11

[eluser]magiclko[/eluser]
Ok... It worked like a charm now Smile Thanks !
#12

[eluser]magiclko[/eluser]
Another doubt... Sad I was going through the video tutorials provided by NetTuts+ guys, In that.. he said, to make function private(i.e. it cann't be called directly from browsers, but it can be called by another methods of the class) we prepend "_" in function name... I was trying to do the same, and than i was calling this function from the view, its not working..

In short, i have a method callMe() in controller site.php and i want that nobody can access it directly via example.com/site/callMe .... but i want this function to be accessible from one of my view... any suggestion on how to do that?

P.S. Apologies for asking so many questions in one thread and acting like a complete noob Sad
#13

[eluser]Shujin[/eluser]
Not possible. If the function is private, the view can't access it.

Think of it like how you want your register function to be able to check if the username is taken. so register would be public, and check_username would be private, because users shouldn't be able to use that.

Code:
function register(){
    ...
    if($this->_check_username($username)){
        ...
    }
}

function _check_username($inUsername){
    ...
}

Something long those lines...

But if you want to send the result from the private function to a view you do something like:
Code:
function register(){
    $data['is_user_taken'] = $this->_check_username($username);
    $this->load->view('view', $data);
}
#14

[eluser]magiclko[/eluser]
Ok... actually i worked around with some variables to get what i desired...i set two variables.. var1 and var2 .. which are initially 0 and 1.. and i am setting var1 equal to 2 in the method which i want user to go through necesaarily before he/she get to the main method... and in this main method i am checking whether var1<=var2 or not..if yes am redirecting to previous method... but thing is, that it works perfectly when user try to access main method directly... but when user follow the normal procedure, var1 is set to 2 and var2 is set to 1 .. and when user comes to main method, and condition is checked, it is still redirecting to previous method..(i.e here var2 is still 1 and var 1 =0) . I have declared var1 and var2 not inside just 1 function.. like this...
class site extends Controller {
private $var1=0,$var2=1;
function index(){}
function method1(){}
function mainMethod(){}

}

Why is it that variables have the same values in mainMethod (i.e 0 and 1)? Any workaround ?
#15

[eluser]Shujin[/eluser]
Hm if I understand correctly, all you want to do is make sure the person runs method1 before mainMethod, and if method1 wasn't complete, yet they tried to get to mainMethod, they would be redirected to method1.

Using URI segments is probably a lot cleaner. Try something like this I suppose:

eg. http://domain.com/install/1
Code:
function install($step = 0){
    $done = FALSE;
    
    switch($step){
        case 1:
            ...
            $done = TRUE;
            redirect(base_url().'install/2';
        case 2:
            if(!$done) {
                redirect(base_url().'install/1';
            }
            ...
        default:
            ...
    }
}

Removes the need to have multiple functions too.
#16

[eluser]magiclko[/eluser]
Nah .. Actually in method1 i am testing whether user should go to mainMethod or not too... so, in nutshell

i don want user to access mainnMethod without passing test in method1...in case anyone attempt to do so, will be redirected to method1..
#17

[eluser]Shujin[/eluser]
Well whatever it is, my way of doing it would take care of that, just need a couple of conditions and you're set.
#18

[eluser]magiclko[/eluser]
Yeah.. thanks a ton.. much cleaner than what i was thinking Smile
#19

[eluser]magiclko[/eluser]
But same problem.... $done is false when install/1 function is called from the view of install/0.... Here is function install...

function install($step=0)
{
$done=FALSE;
switch($step){
case 0:
{
//some code

//some condition checking and $flag is set to 1 or 0 accordingly..




if ($this->flag)
$done=TRUE;

$this->load->view('view_install_0',$somedatapassed);
break;
}
case 1:
{
if(!$done) {
redirect(base_url().'index.php/site/install/0');
}

//some code

$this->load->view('view_install_1',$somedata);

}
}

}

and in view_install_0 i have images to which i have hyperlinked like this...(mentioning just in case here is here)

<a ef=" &lt;?php echo base_url(); ?&gt;index.php/site/install/1"><img src="abc.png" /></a>

:? Confused really... Sad
#20

[eluser]Shujin[/eluser]
Haha, oh right, you need it to somehow keep its state when you redirect.
Look into sessions and session data, that should fix your problem.

no idea what you want to do with the image/link... I guess you want an image to link somewhere, but the image is turning out to be just text?

Code:
<a href=""><img src="&lt;?php echo base_url(); ?&gt;images/abc.png" /></a>




Theme © iAndrew 2016 - Forum software by © MyBB