开发者

Cakephp request action gives me a never ending request loop

I have an element with a requestAction but it gives me a never ending request loop.

For example:

This is my element

<?php $plans = $this->requestAction('profile/Plans'); ?>
<?php foreach($pl开发者_如何转开发ans as $plan): ?>

    <div class="notificationsmall <?php echo $plan['sections']['lable']; ?>">
        <p><b><?php echo $plan['plans']['plan_title']; ?></b></p>
        <p><?php echo $plan['plans']['plan_description']; ?></p>
    </div>  
<?php endforeach;?>

And this is the function that. Its in the "profile" controller

function Plans($id = Null){ 
    $this->set('plans', $this->Plan->Query('SELECT * FROM plans, sections WHERE plans.user_id='.$id.' AND sections.id=plans.section_id'));
}

I have no idea what's wrong.


Is the first piece of code the profile/plans view? If so, you get an infinite loop because the view calls the profile/plans action again, comes back to the same point in the view and so on.

Judging by the code I think you have some misunderstanding on how elements work. You should use the requestAction when you need to insert the element, not inside the element itself.

(I agree with Dunhamzzz that requestAction should be avoided, but sometimes it's not possible. You should consider if using actual elements would work in this case.)


The problem is that you're using RequestAction! Avoid it at all costs. You should create a method in your Plans model that basically returns the contents of the query you're doing, eg

function getByUserId($userId) {
    return $this->find('all', array('conditions' => array('Plan.user_id' => $userId)));
}

Then in your action, just do $this->set('plans', $this->Plan->getByUserId($userId));

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜