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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:25:11+00:00 2026-05-23T12:25:11+00:00

i have a controller page like this: class UsersController extends AppController { var $helpers

  • 0

i have a controller page like this:

class UsersController extends AppController {
var $helpers = array ('Html','Form');
var $name = 'Users';

function index() {
    $this->set('view_users', $this->User->find('all'));
}
}

then i have another controller page like this:

    class PostsController extends AppController {
var $helpers = array ('Html','Form');
var $name = 'Posts';

function index() {
    $this->set('edit_users', $this->Post->find('all'));
}
}

then i have the index file:

<?php foreach($view_users as $value): ?>
<p>id - <?php echo $value['User']['first']; ?></p>
<?php endforeach; ?>

<?php foreach($edit_users as $value): ?>
<p>id - <?php echo $value['Post']['first']; ?></p>
<?php endforeach; ?>

the problem i get is :Notice (8): Undefined variable: view_users [APP\views\posts\index.ctp, line 6]

very strange since the edit_users var works.

What can be the problem?
thanks

  • 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-23T12:25:11+00:00Added an answer on May 23, 2026 at 12:25 pm

    The UsersController and the PostsController are different controllers. They use different views and even though they both have an index action, they are called separately and use different views.

    When you go to /users/index, it calls the index action of the UsersController which sets the $view_users variable.

    When you go to /posts/index, it calls in the index action of the PostsController which sets the $edit_users.

    The problem: You PostsController login action isn’t setting a value for $view_users so the variable is undefined. Assuming that you Post model has a relationship with the User model, you should be able to add this to the PostsController index action to solve your problem:

    $this->set('view_users', $this->Post->User->find('all'));
    

    Alternatively, you could change the view to use empty to check if the variable was set first:

    if ( ! empty($view_users) )
      foreach ( $view_users as view_user )
      {
        // Do something useful.
      }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a controller which loads the view like this: class A extends Controller{
I have a form that looks like this public class ValidationForm { private Person
I have an action like this: public class News : System.Web.Mvc.Controller { public ActionResult
In ASP.NET MVC I have a controller that looks somehow like this: public class
I have my views render to route requests like /controller/action (for instance, /Page/Create), so
I have the following controller: public ActionResult Search(string Name, int? Friend, int? Page) It
This question pertains primarily to good design. Suppose I have a controller action like
I have my main view like this: <%@ Page Title= Language=C# MasterPageFile=~/Views/Shared/Site.Master Inherits=System.Web.Mvc.ViewPage %>
I have a controller for example: class Users extends CI_Controller { function index() {
I have a controller's action and view page that uses a master page. The

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.