CodeIgniter Forums

Full Version: Problem with invalid constant in VIEW
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]Ivan Augusto[/eluser]
Hello, i need assistance =]~

I created this Controller:

Code:
class Projects extends Controller {

    function Projects()
    {
        parent::Controller();    
    }
    
    function index()
    {
        $data['title'] = "Projects";
        $data['projects'] = $this->db->get('projects');
        
        $this->load->view('projects',$data);
    }
}
And this view:

Code:
<html>
<head>
<title><?=title?></title>
</head>
<body>
<table border="1">
    &lt;? foreach ($projects as $project) : ?&gt;
    <tr>
        <td>&lt;?=$project->id?&gt;</td>
        <td>&lt;?=project->name?&gt;</td>
    </tr>
    &lt;? endforeach; ?&gt;
</table>
&lt;/body&gt;
&lt;/body&gt;
&lt;/html&gt;
but I get this message:

Quote:A PHP Error was encountered
Severity: Notice
Message: Use of undefined constant titulo - assumed 'title'
Filename: views/projetos.php

HELP ME PLEASE ;D~

Thks 4all ;]~

El Forum

[eluser]Dam1an[/eluser]
You're missing the dollar sign when printing the table name
change it to
Code:
<td>&lt;?=$project->name?&gt;</td>

El Forum

[eluser]Yorick Peterse[/eluser]
EDIT: Nevermind...

El Forum

[eluser]Ivan Augusto[/eluser]
I fixed and I still get the same thing ;/~

El Forum

[eluser]Dam1an[/eluser]
Oh, missed that one, you need a dollar sign in front of title
Code:
&lt;title&gt;&lt;?=$title?&gt;&lt;/title&gt;

El Forum

[eluser]Ivan Augusto[/eluser]
Uepa! i missing $ in the title, but now is giving problem in foreach, the following error:

Quote:A PHP Error was encountered
Severity: Notice
Message: Trying to get property of non-object
Filename: views/projects.php
Line Number: 14

El Forum

[eluser]tomcode[/eluser]
Code:
&lt;html&gt;
&lt;head&gt;
&lt;title&gt;&lt;?=title?&gt;&lt;/title&gt;

...
Code:
&lt;?=$title?&gt;

the title needs it's $, too

El Forum

[eluser]Dam1an[/eluser]
Whats your current code, cause line 14 is the closing body tag?
When posting your current code, mark the 14th line

El Forum

[eluser]Ivan Augusto[/eluser]
i wasn't watching the right method to call in foreach for printing variable and now everything works fine xD~

CI r0x =]~

Thks man =D~
[]s