Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 5841231
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 22, 20262026-05-22T11:51:47+00:00 2026-05-22T11:51:47+00:00

All, I wanted to know how I could pass a $variable from view, for

  • 0

All,

I wanted to know how I could pass a $variable from view, for example, current article id ( $article[‘Article’][‘id’] ) to the find(‘all’) call in a function in articles_controller.php.

function getRelated($id = null){
$relatedarticles = $this->Article->find(
                    'all',
                    array(
                         'fields' => array(
                        'Article.title'
                        ),
                         'limit' => 4,
                         'order' => 'Article.id ASC',
                         'recursive' => 1,
                         'conditions' => array(
                        'Article.category_id =' => $id
                         )
                         )
                    );

if (!empty($this->params['requested'])) {
    return $relatedarticles;
} else {
    $this->set(compact('relatedarticles'));
}
}

And then from the view, I would call something like this. I cant seem to get this to work… what is the best way to do this?

<div id="articles_view_related">
Related News
<?php 
    $currentid = $articles['Article']['id'];
    $relatedarticles = $this->requestAction('/articles/getRelated/id:$currentid');
    //debug($relatedarticles);
?>
<ul>
    <?php
        foreach($relatedarticles as $relatedarticle){
    ?>
    <li>
        <?php
            echo $relatedarticle['Article']['title'];
        ?>
    </li>
    <?php
        }
    ?>
</ul>

</div>

thank you for all your help

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-22T11:51:48+00:00Added an answer on May 22, 2026 at 11:51 am

    I’m struggling to work out why you are doing this task in this way, but here is your answer nonetheless:

    $relatedarticles = $this->requestAction('/articles/getRelated/'.$currentid);
    

    You don’t need id:$currendId, because of the parameter in your action, anything after /controller/action/ in a URL will be declared as $id in getRelated($id = null); eg: /articles/getRelated/23 and $id will equal 23.


    What you should be doing, is declaring the getRelated() method in your model, and then using the controller action to get the contents, and pass it to the view.
    eg:

    $relatedArticles = $this->Article->getRelated($article['Article']['id']);
    $this->set(compact('relatedArticles));
    

    For data manipulation you want to repeat, stick it in your models 🙂

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

When you run top and see all running processes, I've always wanted to know
I wanted to set some handler for all the unexpected exceptions that I might
My PM just stopped by and he wanted a copy of all of our
The demos for the jquery ui dialog all use the flora theme. I wanted
All front-end developers know the pain of coding for Firefox, then viewing our then
All I know about the constraint is it's name ( SYS_C003415 ), but I
If all tables I want to delete from have the column gamer_id can i
All the articles I've found via google are either obsolete or contradict one another.
All the recent VisualSVN Server posts made me want to check it out. I
All I want is to be able to change the color of a bullet

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.