How to differentiate between controller files/controller methods/ and controller parameters in a url. |
[eluser]lanzd[/eluser]
I'm trying to use ajax in a codeigniter application but I don't know how to tell codeigniter what to use in my url as a file/method/parameter. I have a file located here: application/controllers/admin/manage.php In that file I have a method: Code: public function edit_section($section) { } and I have another method: Code: public function ajax_edit_section() { } I start out in the first method and when the form is submitted I use ajax to submit the form. Ajax then called the 2nd method to insert the data and echo "successful", if it is successful and echo "Failure" if it fails. My jquery ajax files are as so: Code: function formSend(url, status, table, id, date, body1){ Whats happening is, it is taking the value of "url" and using it as the variable to Code: public function edit_section($section) { } How do I tell codeigniter to use it differently? The only Idea I have is if I create a hidden field in my form and give it an absolute path using Code: <?php echo base_url(); ?> I feel there has got to be a better way to do it though, because I really don't want to have my folder structures exposed like that for anyone to see. Thanks, Dan _____________________________________________________ Edit: I forgot to add, I also tried changing this line Code: var url = "ajax_edit_section"; Code: var url = "/admin/manage/ajax_edit_section"; and it does the same thing, the url it goes to is "/admin/manage/admin/manage/ajax_edit_section"
[eluser]InsiteFX[/eluser]
Code: <head> Code: url: base_url + "/admin/manage/ajax_edit_section",
[eluser]lanzd[/eluser]
I'm not familiar with the use of Code: //<![CDATA[]] After looking it up it seems to treat everything with-in it as is, without reading it as code. Kind of like a comment. Now I have this javascript in an external .js file, By using the CDATA will that make the php code work as if it was in a .php file? I'm sorry if I don't follow you on this correctly. Thanks
[eluser]InsiteFX[/eluser]
It is setting the base_url for you to use in your script! Just place that code in your html head section then you can use the base_url in your scripts
[eluser]Matalina[/eluser]
To get the base url in the external javascript file you can parse the location Code: $url = w_indow.l_ocation.href.toString(); I use index.php in my files, you can of course remove everything starting with the i to the last / to remove index.php if you remove index.php remove the underscore it won't let me past it otherwise
[eluser]lanzd[/eluser]
OHH!!! I didn't know you can do that. When you have the javascript call Code: <$cript type="text/javascript" src="myjavascript.js"></$cript> its just like an include. Just think of that external .js file being included on the page as if it wasn't external. So technically I could have 2 external .js files and call a function that is in 1 of them from the other. Kind of bouncing back and forth. Do I have it now? I'm trying it out as we speak.
[eluser]lanzd[/eluser]
Okay, I have a similar question. What if I want my index() function to accept parameters. How would I tell codeigniter to use: Code: www.websitename.com/controller_file/index_variable1/index_variable2 as opposed to Code: www.websitename.com/controller_file/controller_function/index_variable1/index_variable2 I don't know how to have it skip the function portion of the uri and jump directly to variables. Or is this bad practice? should I not use index() in that way? I would of course set default values for any of the parameters. Thanks, Dan
[eluser]lanzd[/eluser]
I'm not sure if I am doing this correctly. My folder structure is as so: website.com/application/controllers //this is where my front end controllers are website.com/application/controllers/admin //this is where my cms portion is I have a controller here website.com/application/controllers/admin/edit_section.php with an method called Code: function index(section = "Default") I want to make it so that I can call Code: www.website.com/admin/edit_section/about_us and go to the index() method of the edit_section.php class with a variable "about_us". I came up with this reroute Code: $route['edit_section/:any'] = "edit_section/index"; But it doesn't seem to do what I'm expecting. I'm going off of what I found here http://ellislab.com/codeigniter/user-gui...uting.html Can I have some help with this? Is it messing up because I have it in a subfolder? |
Welcome Guest, Not a member yet? Register Sign In |