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 8484721
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T20:27:23+00:00 2026-06-10T20:27:23+00:00

(Using PHP style code) Lest imagine we have Controller within which we have array

  • 0

(Using PHP style code)

Lest imagine we have Controller within which we have array of string data:

class Controller {
    private $data = array('a', 'b', 'c', 'd', 'e');
}

Now Controller have to pass that data to View to produce lets say such HTML:

<p>a</p>
<p>b</p>
<p>c</p>
<p>d</p>
<p>e</p>

Question:

Should we pass all the array to View for it to process array data within itself like:

class Controller {
  private $data = array('a', 'b', 'c', 'd', 'e');
  function __construct($data) { // Assigns data array to view
    $view = new View;
    $view->produceHTML($data)
  }
}

class View {
  public function produceHTML($data) {
    foreach($data as $value) {
      echo "<p>$value</p>" . PHP_EOL; // PHP_EOL - PHP Predifined constant (End Of Line)
    }
  }
}

Or we should define different Views for every element like:

class Controller {
  private $data = array('a', 'b', 'c', 'd', 'e');
  function __construct($data) { // Assigns data array to view
    $view = new View;
    $view->produceHTML($data)
  }
}

class View {
  public function produceHTML($data) {
    foreach($data as $value) {
      $this->produceP($value);
    }
  }

  private function produceP($value) {
    echo "<p>$value</p>" . PHP_EOL;
  }
}

Using short data values is just for the example. In most cases I’ve encountered much more complex Views which produce big divs with lots of nested elements.

But what is the best practice to send collection of elements to View?

  • 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-06-10T20:27:24+00:00Added an answer on June 10, 2026 at 8:27 pm

    In proper MVC, the controller shouldn’t “send” any data to the view. The view is an active layer of the application which should retrieve data from the model layer. The controller should only change the state of the model, but shouldn’t retrieve any data.

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

Sidebar

Related Questions

Using php I am trying to get some data from a .csv file which
i have this following php code : $filename = '/front/style.css'; $cssfile='#h1{font-size:12px}'; if($id_file=fopen($filename, w+)) {
Is it possible to deny from all apache htaccess style using php. I can't
I am using Twitter Bootstrap to style validation_errors for a registration page: <?php echo
Using PHP, I can convert MySQL data or static table data to csv, Excel,
I'm running a third party script by using a wrapper class I've written which
I have some variables stored using php and an html textarea. I would like
Here is the code from my style.php script The objective: User should be able
I need your help. I have tables using PHP while looping and I need
I am using PHP to try and update information I have in a mysqli

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.