Welcome Guest, Not a member yet? Register   Sign In
URI parameter & function parameter conflict
#1

[eluser]Computerzworld[/eluser]
Hello,
I am using one function using URI directly with passing parameters to it like this.

Code:
http://localhost/myProject/myController/myFunction/p1/v1/p2/v2/p3/v3

I am using the same function from within another function like this.

Code:
myNewfunction()
{
    $this->myFunction($val1,$val2,$val3);
}

But when I use the function using URI, it takes the URI parameter values as function parameter and I don't want to do this. As CI is assigning the URI parameters to function parameters directly. Is this possible anyhow? If yes then how can I do this? Please help me. Thanks in advance.
#2

[eluser]TheFuzzy0ne[/eluser]
Sorry, but I for one am totally lost. If you're talking about controller methods, then yes, CodeIgniter will pass those URI arguments into the method. What is it that you don't want it to do this?
#3

[eluser]Computerzworld[/eluser]
Actually what I want is when I am calling the function from URI it should not take the value as function parameter as I am passing 3 parameters from other function. Is it possible?
#4

[eluser]TheFuzzy0ne[/eluser]
I'm still confused...

Right, CodeIgniter automatically passed all of the URI segments into the method as arguments. It's up to you whether or not you use it like this. Even though CodeIgniter passes the segments into the method like this, there's nothing saying that they are the arguments you have to use. However, my question still stands - why not do it this way? We are talking about a controller method here, aren't we? Unfortunately, you're originally post doesn't seem to provide enough context to the problem, hence my confusion.
#5

[eluser]Computerzworld[/eluser]
Actually why I want to do this is that when I will be using it from URI by clicking on link, it will be using parameters from URI and when I will be using it from another function it will be using function arguments. I am having several if conditions to separate out from where its called. So, when I will be using it from URI, all the function arguments should be blank and I am getting first URI parameter as first function argument, second URI parameter as second function argument and likewise. And what I want is that when the function is called from URI all the parameters should be blank. I think I got the solution while writing this reply Smile... Let me check whether it works... I will post it if I will get the solution. Thanks.
#6

[eluser]Computerzworld[/eluser]
Its a quite simple solution that I found...

Here is what I have done...

I have checked for if URI parameters exists in the function myFunction(). So, if they are available then I have reset the function arguments. So, when it is called from URI , function arguments will not be taken into consideration and when it will be called from another function the arguments will be used. HTH... Thanks.
#7

[eluser]TheFuzzy0ne[/eluser]
I'm still grappling to understand why you'd want to reset the arguments to the controller method. If you specify parameters, then they will be populated, otherwise, they won't be. I can't understand why you'd want to specify those parameters if you don't want to use them. I'm sure I'm missing something here. I guess this is just one of those things I'm going to have to file in my X-Files cabinet.

I think I understand what you're trying to do, but I still don't understand why.
#8

[eluser]Computerzworld[/eluser]
Oh... let me explain the case what I had done exactly.

I am having one function which will send an email to users when I click on the link send. It will be having id of email as URI parameter so it will be fetching the particular email data from the database and will send an email. So, my function will be something like this.


Code:
http://localhost/myProject/myController/send/emailId/1

Same way I want to send the email to the user when he will fill up the data in the form for saving those emails in the database. User will be filling up the form and the posted data will be used to send emails. So, I have called this send function in another function that is saving the posted data. I am passing the posted data as function arguments. So, they will be used to send email. Here is my send function.

Code:
function send($param1='',$param2='',$param3='')
{
......
}

Now when I will be calling this function from the send link, I will be passing emailId as parameter in the URI like this.

http://localhost/myProject/myController/send/emailId/1

So, $param1 will be having value emailId and $param2 will be having value 1. That should not happen. That's why I have reset the arguments in the function if I found the emailId in the URI. So, the same function can be used to perform two actions. That was my basic need. And I did it by doing simple tweak.

Hope you will clearly understand what I have tried to explain you.

Thanks.




Theme © iAndrew 2016 - Forum software by © MyBB