简体   繁体   中英

CakePHP controller action not firing

I'm a beginner at CakePHP, and for a project at work I'm running into a maddening problem. I have a paginated list of links with each linking to a view in cakephp:

link1: <a href="<?php echo $SITE_URL>/users/show_chart/<?php echo $id0;?>">See Chart</a>
link2: <a href="<?php echo $SITE_URL>/users/show_chart/<?php echo $id1;?>">See Chart</a>
link3: <a href="<?php echo $SITE_URL>/users/show_chart/<?php echo $id2;?>">See Chart</a>

Pretty simple. I'm inheriting the project from a previous team, so there's some code I don't understand yet, but I think it's pretty clear that it should be calling the "show_chart" action function in the "users_controller" class.

Inside that function I've tried various things like:

function show_chart($id) {
echo "<pre>";
echo $id;
echo "</pre>";
echo "You'd better show me something";
exit;
} 

But when I click on one of the links, it performs the action as though I never edited the action at all in the controller. My little debug message never shows up. The program even works as usual when I comment the "show_chart" function out wholesale.

My first thought was that there's an HTTP redirect somewhere, but I can't find anything amiss. My second thought was that this action is somehow cached somewhere and the function is getting bypassed in favor of the caching. Any thoughts? Anyone?

Check the router. That will tell you exactly which action & controller are called by that URL.

In principle, you're right. /users/show_chart/ goes to the users controller and the show cart function.

What in your case would be useful would be to download all the code you have and create a project in some IDE, so you can search through the whole project. I've always used eclipse with CakePHP, but many alternatives exist. Most likely, you could just start off with Notepad++ and search google to see how you can look through all files in a folder. Then, just search for 'show_cart' and you're done!

Other than that, it can be in a few places depending on the quality of the team before you... the .htaccess, the router, the bootstrap, the users controller, a random php script...

Good luck!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM