Welcome Guest, Not a member yet? Register   Sign In
Problem with invalid constant in VIEW
#1

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

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

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

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

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

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

[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
#8

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

[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




Theme © iAndrew 2016 - Forum software by © MyBB