开发者

CakePHP requires an action where it's not needed/used [closed]

It's difficult to tell what is being asked here. This question is ambiguous, vague, incomplete, overly broad, or rhetorical and cannot be reasonably answered in its current form. For help clarifying this question so that it can be reopened, visit the help center. Closed 10 years ago.

The address of my website is localhost/hogeacts/<controller>/<action> [or so it would have me think].

There are a couple of files [I stripped them down to the necessary] involved in this problem:

T开发者_运维知识库he controller

class FactsController extends AppController
{      
    var $name = "Facts"; 
    var $helpers = array('Javascript');

    function index(){}        
    function latest($count)
    {
        // Uses a blank Layout so I get the JSON out of it
        $this->layout = 'ajax';

        // Model defined function, I still like fat models - skinny controllers
        $facts = $this->Fact->getLatest($count);

        $this->set('facts', $facts);
    }

The view

<div id="content"></div>

<div id="scripts">
    <?php echo $javascript->link('index', false) ?>
</div>

The script

var index_obj = {
    init: function() {
        $.ajax({
            url: "/facts/latest/2",
            success: function(r)
            {
                $("#content").hide();
                $("#content").html(r);
                $("#content").fadeIn();
            }
        });
    }
}

$(function() {
    index_obj.init();
});

The 'partial view'

<?php echo $this->element('factlist', array('facts' => $facts)); ?>

There is also The element but that is just for displaying and I really don't think it has anything to do with the error.

Now, whenever I access localhost/hogeacts/facts I get the right result, everything seems to be working just as expected, the javascript loads, calls the partial view which calls the element and they get displayed in the #content div. So far so good, but if I access localhost/hogeacts/facts/index which should do exactly the same thing, I get:

The error

Missing Method in FactsController

Error: The action facts is not defined in controller FactsController

Error: Create FactsController::facts() in file: app\controllers\facts_controller.php.

<?php
class FactsController extends AppController {

    var $name = 'Facts';


    function facts() {

    }

}
?>

What am I missing?


It seems that in my JavaScript I was calling url: "/facts/latest/2" when I should have been calling url: "latest/2" without respecifying the controller. It interpreted facts as being an action instead of the controller so that's why I go the error

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜