Welcome Guest, Not a member yet? Register   Sign In
Anchor URL helper calls page not function
#1

[eluser]edziffel[/eluser]
I am trying to use the anchor url helper to call a function on the main controller.

Code:
class Drawback extends CI_Controller {
    
    
    function Drawback() {
        parent::__construct();
        $this->load->helper('url');
    }

Blah Blah (skipped functions that work fine)

Code:
function db_upload() {
        $data['title'] = "EZ Uploader";
        $data['heading'] = "Upload Source files here.";
        $data['directions'] = "Browse to Source file.  Browse to desired table";
                
        $this->load->view('db_upload_view', $data);
    
    }

on the index page have the following anchor set up which generates a proper link

Code:
<?php echo anchor('drawback/db_upload', 'Upload Source Files'); ?>

Problem is that instead of calling the db_upload function, it is looking for a page called db_upload and gives me the error:

The requested URL /localhost/drawback.com/index.php/drawback/db_upload was not found on this server.

which if that is what it is looking for is correct as it doesn't exist. Need to get it to call the function on the main controller instead. What am I doing wrong?

Thanks
#2

[eluser]LynxCoder[/eluser]
Sounds like something to do with routing to me. Have you changed anything in the application/config/routes.php file?
#3

[eluser]edziffel[/eluser]
Yes. Changed the default to drawback

Code:
$route['default_controller'] = 'drawback';
$route['404_override'] = '';

Was looking at that myself. Was thinking that I should be getting the 404 error code instead of the not located on the server error. Bad install? Server glitch/configuration problem? Stock linux lamp server installed using tasksel.

Databases work fine. Was able to pull sample data into tables on test page. Can manually type in url and db_upload_view page loads just fine.

Can't follow CI tut like with 1.7. Outdated.

Ideas?
#4

[eluser]Mirge[/eluser]
[quote author="edziffel" date="1311290320"]
Code:
<?php echo anchor('drawback/db_upload', 'Upload Source Files'); ?>

Problem is that instead of calling the db_upload function, it is looking for a page called db_upload and gives me the error:

The requested URL /localhost/drawback.com/index.php/drawback/db_upload was not found on this server.
[/quote]

anchor('drawback/db_upload') will give a link to drawback/db_upload... I'm not sure what the problem is?

drawback is the controller it's accessing, with db_upload being the method.
#5

[eluser]edziffel[/eluser]
Did some other tests and CI is definitely not working properly. Did the fresh CI install with new download, and no better results. Have to think the issue is on my machine. Could be... I really like linux, but it sure as heck ain't perfect. "Updating" -I knew better lol- to studio put some weird in it, as in sometimes it boots the first time and then maybe not. Also have machine triple booted and booting to windows and then linux always causes a do it twice boot. Who knows and up until now, who cares? Also tweaked apache config to allow larger upload sizes.

Need to isolate problem so did a fresh linux install on a different machine. Have to get all the extras, code editor, lamp, etc. up and running. Am working through it as time allows. Should have time by end of weekend. Will post resolution.
#6

[eluser]Mirge[/eluser]
I think the problem is a lack of understanding. Not trying to be rude, but as I said in my earlier post, CI was doing exactly as it was told.
#7

[eluser]edziffel[/eluser]
Yes. I know what you mean. If you look up anchor in the users guide,
http://ellislab.com/codeigniter/user-gui...elper.html
then you arrive at the conclusion that you are referring to.

However if you check out the tutorial linked to on the home page under video tutorials
http://codeigniter.com/tutorials/
reference the part where the comments link is being added to the database view page in the second tutorial it looks like if you specify in the url the controller, then the next part of the URL becomes a call to a function. IE, using my controller, ....... drawback/db_upload. Which is or isn't working depending on whether you want the web page or what I want, the call to the function on the controller.

That being said, I could easily move the function to the db_upload_view.php page and use the anchor function to call it, but doesn't that defeat the whole idea of using a controller page?

Maybe the question I need to ask is if like you say, the anchor function isn't going to work to call a function on the controller page, than how should I go about it?

The reinstall is all about getting a proper working system to eliminate unseen grief from that. Learned over the years to clean up the whole thing not just part if you want good results. :-)
#8

[eluser]Mirge[/eluser]
[quote author="edziffel" date="1311462147"]Yes. I know what you mean. If you look up anchor in the users guide,
http://ellislab.com/codeigniter/user-gui...elper.html
then you arrive at the conclusion that you are referring to.

However if you check out the tutorial linked to on the home page under video tutorials
http://codeigniter.com/tutorials/
reference the part where the comments link is being added to the database view page in the second tutorial it looks like if you specify in the url the controller, then the next part of the URL becomes a call to a function. IE, using my controller, ....... drawback/db_upload. Which is or isn't working depending on whether you want the web page or what I want, the call to the function on the controller.

That being said, I could easily move the function to the db_upload_view.php page and use the anchor function to call it, but doesn't that defeat the whole idea of using a controller page?

Maybe the question I need to ask is if like you say, the anchor function isn't going to work to call a function on the controller page, than how should I go about it?

The reinstall is all about getting a proper working system to eliminate unseen grief from that. Learned over the years to clean up the whole thing not just part if you want good results. :-)[/quote]

anchor() is working exactly as it says it does. I'm not sure where exactly you're getting confused.

Example syntax would be: anchor("controller_class/method_name")

Which would access method_name() method in controller_class.

The second argument supplied to anchor() would be the link text you want to use. IE: "click here to access method_name."
#9

[eluser]edziffel[/eluser]
Quote:anchor() is working exactly as it says it does. I’m not sure where exactly you’re getting confused.

Me neither.

Quote:Example syntax would be: anchor(“controller_class/method_name”)

Which would access method_name() method in controller_class.

Yes.

Code:
<?php echo anchor('drawback/db_upload', 'Upload Source Files'); ?>


drawback is my controller class and db_upload, the function defined in the controller is supposed to be the method in this. At least that is how I thought it was going to work.

What I really need to do is to be able to call the function from a link. If anchor doesn't work, what would?
#10

[eluser]Mirge[/eluser]
[quote author="edziffel" date="1311471130"]
Quote:anchor() is working exactly as it says it does. I’m not sure where exactly you’re getting confused.

Me neither.

Quote:Example syntax would be: anchor(“controller_class/method_name”)

Which would access method_name() method in controller_class.

Yes.

Code:
<?php echo anchor('drawback/db_upload', 'Upload Source Files'); ?>


drawback is my controller class and db_upload, the function defined in the controller is supposed to be the method in this. At least that is how I thought it was going to work.

What I really need to do is to be able to call the function from a link. If anchor doesn't work, what would?[/quote]

Code:
echo anchor('drawback/db_upload');

This ISN'T calling the db_upload() method in your drawback class?




Theme © iAndrew 2016 - Forum software by © MyBB