You cannot access the model or controller functions from the view, you
must do so before the view is rendered and pass whatever information
you can to the view. In the view, you can then access the information
in a loop because the data passed will be in array form.
Therefore, in your controller you can do this:
$this->users = $this->Regusers->findAll();
$this->set('someUsersHere', $this->users);
Then in view, you access the variable by the name that you put in
single quotes. $someUsersHere
Now $someUsersHere is an array that the your view(ctp file) can access
to display the data.
foreach($someUsersHere as $users)
{
//exec code here
}
or
foreach($someUsersHere as $key => $value)
{
//exec code here
}
Also, I noticed your model class declaration reguser doesn't have a
capital 'R'... make sure that it does.
On Jun 1, 2:01 pm, cakephpnewbie <[EMAIL PROTECTED]> wrote:
> Hi All,
> I am new to cakePHP. I am trying to create a view which displays the
> data from the table 'regusers'.
>
> ------------------------------------
> The model - reguser.php
> ------------------------------------
> <?php
> class reguser extends AppModel
> {
> var $name = 'Reguser';}
>
> ?>
>
> ---------------------------------------------------------
> The controller - regusers_controller.php
> ---------------------------------------------------------
> <?php
> class RegusersController extends AppController
> {
> var $name = 'Regusers';
>
> function report()
> {
> $this->pageTitle = "USER REGISTRATION REPORT";
> }
>
> }
>
> ?>
>
> ------------------------------
> The view - report.ctp
> ------------------------------
> <HTML>
> <HEAD>
> <TITLE>USER REGISTRATION REPORT</TITLE>
> </HEAD>
>
> <BODY>
> <CENTER><H2>USER REGISTRATION REPORT</H2></CENTER>
> <HR>
>
> <?PHP
>
> ECHO "<CENTER>";
>
> //FORMATTING QUERY OUTPUT
> ECHO "<TABLE BORDER=2 CELLSPACING=5 CELLPADDING=5>";
> ECHO "<TR BGCOLOR=#999999><TD><B>USER ID</B></TD><TD><B>USERNAME</B></
> TD><TD><B>EMAIL</B></TD><TD><B>DATE OF REGISTRATION</TD></B></TR>";
> $COLOR = 1;
>
> //ITERATE OVER RECORD SET AND PRINT EACH FIELD
> foreach ($this->Reguser->findAll() as $reguser)
> {
> IF ($COLOR == 1)
> {
> ECHO "<TR BGCOLOR=#CCCCCC>";
> $COLOR = 0;
> }
> ELSE
> {
> ECHO "<TR BGCOLOR=#FFFFFF>";
> $COLOR = 1;
> }
> ECHO "<TD>" .$reguser['id'] ."</TD>";
> ECHO "<TD>" .$reguser['uname'] ."</TD>";
> ECHO "<TD>" .$reguser['uemail'] ."</TD>";
> ECHO "<TD>" .$reguser['date'] ."</TD>";
> ECHO "</TR>";}
>
> ECHO "</TABLE>";
> ECHO "</CENTER>";
>
> ?>
>
> </BODY>
> </HTML>
>
> I have changed the database.php file to map to my table regusers.
> The problem is when i type the addresshttp://localhost/regusers/report
> in the browser window, I get the error:
> Fatal error: Call to a member function on a non-object in C:\AppServ
> \www\cakephp\app\views\regusers\report.ctp on line 20
> Line 20 is foreach ($this->Reguser->findAll() as $reguser)
> Can someone please help me understand what this error message
> indicates?
> Thanks in advance!!
>
> Regards,
> phpnewbie
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---