• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Retrieve controller namd and function name from url

#11
[eluser]CroNiX[/eluser]
Why not just use your regular controller and not have a separate ajax controller? I use forms with the action submitting to the class/method for that form, but also use the same class/method to validate the form if it was submitted via ajax. Why the duplication? Is the data somehow different if submitted via ajax?

Edit:
It seems the only difference would be in how you return anything, in which case you could use
Code:
if ($this->input->is_ajax_request())
and return either json or html (or whatever you're doing)

#12
[eluser]C.T.[/eluser]
I think URI helper will do what u want to have

http://cisite.com/controller1/
Code:
$this->uri->segment(1)
Return:controller1

http://cisite.com/controller1/dosomething
Code:
$this->uri->segment(1)
Return:controller1
Code:
$this->uri->segment(2)
Return:dosomething

http://cisite.com/controller1/dosomething/action/
Code:
$this->uri->segment(1)
Return:controller1
Code:
$this->uri->segment(2)
Return:dosomething
Code:
$this->uri->segment(3)
Return:action

#13
[eluser]coldscooter[/eluser]
It's more complicated than it seems. My goal is actually trying to avoid having any duplication at all. Basically, libraries will be loaded that require a controller name and method name, and i want the flexibility of being able to parse a string in some instances as well as reading from the current router class.

#14
[eluser]CroNiX[/eluser]
@C.T. The URL helper will only gets data from the current url, which is not what he is after.

#15
[eluser]coldscooter[/eluser]
Wow, no-one is understanding my question. Sorry, i may have explained it a little vaguely at first. Please read my more recent posts.

#16
[eluser]CroNiX[/eluser]
I understand your question just fine. Why you want to do it this way is what I don't understand. There just isn't anything that will do what you want, unless your app stays exactly the same as it is.

You can keep doing what you are doing, however if your app changes and you add a subdirectory to your controller directory (like you want all admin controllers in an admin directory for separation), or you start using routes, your method will no longer work as you can remove controller names and method names from the url to provide neater urls. However, I would make it more robust and actually check if $segments[0] is an actual file that exists in /application/controllers before assuming it is correct and trying to use it (unless all of your urls will always start with controller/method and it will never deviate from that).

I think you should rethink your approach as it's not very scalable and has more overhead.

#17
[eluser]C.T.[/eluser]
it because you said "I am passing a local url to a function in codeigniter as a $_GET parameter"

I can't see the point that why are you need to use a old URL format but not the "/" directly like REST services and write a controller or library to handle that?

Sorry for misunderstanding!

#18
[eluser]coldscooter[/eluser]
Yeah i agree it's not robust or scalable.

I will rethink my approach. Pretty sure i can do it by just adding an ajax function to MY_controller so that all my other controllers inherit this function.

Thanks for your help all.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.