Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
597 views
in Technique[技术] by (71.8m points)

cakephp routing - pages_controller/home.ctp error only on debug=0

When core.php debug is set at 1 or 2 and I browse to the root of my cakephp site I get expected result, the page served is correct, ie, PagesController default() action -> home.ctp

However if I change debug to 0 I get the the following error:

Error: The requested address '/' was not found on this server.

My router.php file contains:

    Router::connect('/', array('controller' => 'pages', 'action' => 'display', 'home'));
/**
 * ...and connect the rest of 'Pages' controller's urls.
 */
    Router::connect('/pages/*', array('controller' => 'pages', 'action' => 'display'));

I have tried deleting all cache files and removing CAKE cookies, and other actions work as expected when visited directly, eg, /user, /groups, etc. Problem only occurs when hitting the root '/'.

I am using cakephp 1.3.4 and ACL + Auth.

Edit ** I'm including the code for the default() function from pages_controller.php

/**
 * Displays a view
 *
 * @param mixed What page to display
 * @access public
 */
    function display() {

        $path = func_get_args();

        $count = count($path);
        if (!$count) {
            $this->redirect('/');
        }
        $page = $subpage = $title_for_layout = null;

        if (!empty($path[0])) {
            $page = $path[0];
        }
        if (!empty($path[1])) {
            $subpage = $path[1];
        }
        if (!empty($path[$count - 1])) {
            $title_for_layout = Inflector::humanize($path[$count - 1]);
        }
        $this->set(compact('page', 'subpage', 'title_for_layout'));
        $this->render(implode('/', $path));

    }
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

OK the answer is so simple it is embarassing: in home.ctp there is the following code:

if (Configure::read() == 0):
    $this->cakeError('error404');
endif;

Configure::read() by default read var debug - therefore it throws this error if debug is set to 0.

Thanks to Benjamin for putting me on the right track. Cake is wonderful and at the same time infuriating until you know the basics!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...