Welcome Guest, Not a member yet? Register   Sign In
Call controller function outer folder
#1

(This post was last modified: 02-04-2016, 02:49 PM by slipdiegoknot.)

Hi friends I have a controller inside a folder but I can't call a function from a controller in a parent folder using AJAX.
(codeigniter 3.0.0)
application
----controllers
     c_main.php
     cf_folder
     -------c_inner_ctrl.php
----views
     ----my_view.php
public
----js
     ----jslogic.js
So c_inner_ctrl loads the view called my_view ($this->load->view->('my_view'))
The view (my_view) imports a javascript file called jslogic.js is this JS file there is a function that calls a function from c_inner_ctrl.php
and it works fine. NOW! if from this very JS file I want to call a function in c_main.php I get the error in google chrome's console
POST http://localhost/my_project/cf_folder/c_main 404 (Not Found)

This means that I am not able to call a CONTROLLER function from another view which its controllers is in another folder


Here is the js function (this one works)
Code:
function probar() {
                $.ajax({
                    url  : 'c_inner_ctrl/function_works',
                    async: false,
                    type : 'POST'
                 })
                 .done(function(data){
                    console.log(data);
                 });
            }
this one doesn't

Code:
function probar() {
                $.ajax({
                    url  : 'c_main/function_doesnt_work',
                    async: false,
                    type : 'POST'
                 })
                 .done(function(data){
                    console.log(data);
                 });
            }
Reply
#2

Your error message provides a clue to the problem ... you are linking to c_main inside the cf_folder, where your c_inner_ctrl is.
You should be linking one folder higher.

You have misread/misunderstood the error message, and are drawing an inappropriate conclusion.

If you set up virtual hosting, mapping a local domain to your htdocs/my_project, then your link references could be absolute, i.e. "/cf_folder/c_inner_ctrl" and "/c_main".
Reply
#3

(02-03-2016, 05:23 PM)ciadmin Wrote: Your error message provides a clue to the problem ... you are linking to c_main inside the cf_folder, where your c_inner_ctrl is.
You should be linking one folder higher.

You have misread/misunderstood the error message, and are drawing an inappropriate conclusion.

If you set up virtual hosting, mapping a local domain to your htdocs/my_project, then your link references could be absolute, i.e. "/cf_folder/c_inner_ctrl" and "/c_main".

Hi! how do I do that? If I write in the url parameter: 'c_main/function_doesnt_work'
it produces the error I described.
If I try that something concats my url value to the folder I am already in and produces cf_folder/c_main
where cf_folder is the folder where I am and concats c_main (the controller I am aiming)
I cannot point to a controller in a higher folder.
Reply
#4

Well I managed doing it this way: ../c_main/function
Reply
#5

(This post was last modified: 02-05-2016, 08:59 AM by keulu.)

you can try with a <base url="<?php echo base_url(); ?>" /> in the <head> of your layout
Reply




Theme © iAndrew 2016 - Forum software by © MyBB