[SOLVED] controller not passing Data to my veiw

#1
[eluser]Neocrypter[/eluser]
Ok so the second installment of Neo needs help and feels like a tard is as follows.

My controller is not passing data to my my veiw, or im not reading the error im getting correctly as its been many years since ive worked with php, somewhere around php 3 Tongue.

Here is my controller
Code:
<?php
class Banned_user extends Controller{
    private $data;
    function Banned_user(){
        parent::Controller();
        $this->load->database();        
        $this->load->scaffolding('banned_users');
        
    }
    function index(){
        $this->load->model('banned_users_model','bu');
        $data['query'] = $this->bu->get_entries();
        //$data['title'] = 'Banned Users';
       // $data['page'] = 'banned_users';    
        $this->load->view('banned_users', $data);    
    }
    
}
?>

here is the foreach loop in my veiw
Code:
<?php foreach($query as $row):?>

<li>&lt;?php echo $banned_user_slname;?&gt;</li>
<hr />

&lt;?php endforeach;?&gt;

and lastly here is there error
Quote:A PHP Error was encountered

Severity: Notice

Message: Undefined variable: banned_user_slname

Filename: views/banned_users.php

Line Number: 6

thanks in advance.

#2
[eluser]Italo Domingues[/eluser]
Read the documentation for CI and search the forum, that kind of questions surely must have some topic

Change your code

Code:
&lt;?php foreach($query as $row):?&gt;

<li>&lt;?php echo $banned_user_slname;?&gt;</li>
<hr />

&lt;?php endforeach;?&gt;

For

Code:
&lt;?php foreach($query as $row):?&gt;

<li>&lt;?php echo $row['name']; ?&gt;</li>
<hr />

&lt;?php endforeach;?&gt;

#3
[eluser]mi6crazyheart[/eluser]
Hey!!! i feel u r doing some thing wrong in u'r view file in that foreach loop. It should be like this...

ex:
Code:
foreach($query as $item):
$headlineId = $item->headline_id ; // "headline_id" is one of the field which has accessed from DB table
echo $headlineId;

Hope u've got the idea...

#4
[eluser]Neocrypter[/eluser]
thanks mi6crazyheart, that worked great, i was following along the CI video tutorial and the way i had it was the way they were doing it, also i looked at the user manual and thats the way they had it as well, so I was at a complete loss, ive been looking on the forums and google for the better part of an hour or more before I posted here on this.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.