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

  • SEARCH
  • Home
  • 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 3305718
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T21:12:10+00:00 2026-05-17T21:12:10+00:00

Imagine a typical CakePHP application, in which a Controller passes various bits of data

  • 0

Imagine a typical CakePHP application, in which a Controller passes various bits of data to the View using $this->set in the typical way:

class ThingsController extends AppController {
    function test() {
        $this->set('someparam', 5);
    }
}

If the corresponding View was to define and use a small helper function which outputs some HTML, is there any way to access that variable $some_param from within the function? I would have thought you could just access it as a global variable, but it always come out with the value NULL.

<?php
function helper_function() {
    global $someparam;
    echo var_dump($someparam); // Just prints NULL
}
?>
<h1>I am a View!</h1>
<?php helper_function(); ?>

To be honest, an even simpler use case is for the helper_function to be able to access things like the $html and $javascript helpers.

  • 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-17T21:12:11+00:00Added an answer on May 17, 2026 at 9:12 pm

    In the situation you describe, you’re going to be operating on the value after you’ve set it for the view. You may or may not be changing that value. Either way it could get confusing. It would be clearer – and make life easier when you’ve forgotten how this app works – to do something like

    function test() {
        $myVar = 5;
        $this->helper_function($myVar);
        $this->set('some_param', $myVar);
    }
    

    As for accessing the helper functions, you can do this and there are times when there doesn’t seem to be an alternative, but it is best avoided wherever possible as it breaks MVC.

    This:

    <h1>I am a View!</h1>
    <?php helper_function(); ?>
    

    just isn’t right (assuming you have written the function in the controller). I would be calling that function in the view’s controller action and passing the result out as a variable. Just try to remember, use the controller to prepare data for the view. Use the view to display the data.

    Why not write your own helper? That would appear to be the way to solve your problems.

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

Sidebar

Related Questions

Imagine the typical type of application where you have a list of items with
Imagine I've got a database with lots of data, from which users can search.
Imagine a very big gwt project of application. This is just a some form
Imagine this C++ code (which uses clang's blocks language extension). auto now = std::chrono::system_clock::now();
Imagine a set of data with given x-values (as a column vector) and several
imagine this html on a page <div id=hpl_content_wrap> <p class=foobar>this is one word and
Imagine you have class A which has code which runs as method M. And
Imagine your typical manager / employee hierarchy, where you have an employee with a
Ok, imagine a typical scenario, - there is a thread object and comments, attached
I have a WPF application which so far has been client only, but now

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.