CodeIgniter Forums
Problem with invalid constant in VIEW - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: CodeIgniter Archived (from EllisLab) (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: Problem with invalid constant in VIEW (/thread-18323.html)



Problem with invalid constant in VIEW - El Forum - 05-02-2009

[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 ;]~


Problem with invalid constant in VIEW - El Forum - 05-02-2009

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



Problem with invalid constant in VIEW - El Forum - 05-02-2009

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


Problem with invalid constant in VIEW - El Forum - 05-02-2009

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


Problem with invalid constant in VIEW - El Forum - 05-02-2009

[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;



Problem with invalid constant in VIEW - El Forum - 05-02-2009

[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



Problem with invalid constant in VIEW - El Forum - 05-02-2009

[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


Problem with invalid constant in VIEW - El Forum - 05-02-2009

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


Problem with invalid constant in VIEW - El Forum - 05-02-2009

[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