0

I have a question about using parameters from the controller in the view.
This is my situation:

In my Controller I have :

foreach ($projects as $project) {
    $projectTitle = $project->getName();
}

Now In my view I want to show every title from a project in a table.
How can I do this the right way? I also want to create a link with in my view like this :

"controller/action/projectid/1"

to edit the project.

1 Answer 1

1

Why not have an array called $titles and do an array_push inside the for loop like this:

array_push($titles,$project->getName())

And send the $titles directly to the view?

Sign up to request clarification or add additional context in comments.

2 Comments

And then loop through the array $titles in my view?
Yes..Exactly. A better way is to make sure you send the $projects array into the view itself if your view can use getName on each $project object. You can also look for generating $projects as an array of arrays so that you can send it straight to the view

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.