• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Display related data from user profile

#11
[eluser]doubleplusgood[/eluser]
This is my updated controller for the profile/view;

Code:
function view($username){
            $this->load->model('dealers_model', 'dealers', TRUE);
            $view_data['username'] =  $username;
            $view_data['title1'] = "Dealer";
            $view_data['title2'] = "Profile";
            $view_data['title'] = "Dealer Profile";
            $view_data['body'] = "dealerpage";
            $view_data['dealers'] = $this->dealers->getAllDealers();
            $view_data['featured'] = $this->profile_model->getFeaturedVehiclesByUser();
            $view_data['view_file'] = 'dealers';

            if ( $username === FALSE )
            {
                redirect('profile');
            }
            
            $view_data = array();
            $view_data['profile'] = $this->profile_model->get_single_profile($username);
            
            if ( $view_data['profile'] === FALSE )
            {
                redirect('profile');
            }
            
            $view_data['view_file'] = 'profile/view';
            
            $this->load->view('layout', $view_data);
        }


Which is calling the getFeaturedVehiclesByUser(); from the profile_model.

My view looks like this;

Code:
<?php
    if(is_array($featured) && count($featured)>0){
    ?>
    <?php foreach ($featured as $item) { ?>

        <div class="activity-item">
       <div class="activity-item-image"><img src="../images/featured-car.jpg" alt="#" /></div>
        <div class="activity-item-bottom">

        <ul>
        <li><a href="#"><a ></li>
        <li>£50</li>

        </ul>

        </div>
    &lt;?php
    }
    ?&gt;
    &lt;?php
    }
    else{
    ?&gt;
    <p class="noresults">No featured vehicles found.</p>
    &lt;?php
    }
    ?&gt;

Not sure if this is correct or not. Sad

#12
[eluser]Zack Kitzmiller[/eluser]
Code:
function view($username){
            $this->load->model('dealers_model', 'dealers', TRUE);
            $view_data['username'] =  $username;
            $view_data['title1'] = "Dealer";
            $view_data['title2'] = "Profile";
            $view_data['title'] = "Dealer Profile";
            $view_data['body'] = "dealerpage";
            $view_data['dealers'] = $this->dealers->getAllDealers();
            $view_data['featured'] = $this->profile_model->getFeaturedVehiclesByUser();
            $view_data['view_file'] = 'dealers';

            if ( $username === FALSE )
            {
                redirect('profile');
            }
            
            $view_data = array();
            $view_data['profile'] = $this->profile_model->get_single_profile($username);
            
            if ( $view_data['profile'] === FALSE )
            {
                redirect('profile');
            }
            
            $view_data['view_file'] = 'profile/view';
            
            $this->load->view('layout', $view_data);
        }

This is really here nor there, but it would be beneficial to call

Code:
if ( $username === FALSE )
            {
                redirect('profile');
            }

Before anything else in your controller. 1st, you're gonna get a notice about setting $data['username'] = $username, and why bother wasting the memory to fill that array is you're just going to destroy it anyway?


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


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