Welcome Guest, Not a member yet? Register   Sign In
Using functions set in a model? [SOLVED]
#6

[eluser]TheFuzzy0ne[/eluser]
Controller:
Code:
class Profiles extends Controller
{
    function Profiles()
    {
        parent::Controller();
        $this->load->model('Profile_Model', 'profile');
                
    }
    function index()
    {
        if ( !$user = $this->uri->segment(1))
        {
            $user = "home";    
        }
        
            //START of twitter section
            $ti = $this->profile->twitter_info_public($user); // Get the data from the model method - changed
                print_r($ti);
            $this->load->library('twitter'); // Load the library
                
            $config = array(
                    'userid'            => $ti['id'], // changed
                    'username'          => $ti['username'], // changed
                    'type'              => 'mine',
                    'num'               => 5,
                    'rss_cache_path'    => APPPATH.'cache/twitter-rss-cache',
                    'cache_time'        => 300 // 5 minutes
                    );
                // $config['type'] can be 'mine' (just your own tweets),
                // or 'social' (includes people you follow)
                
            $this->twitter->init($config);
                
            $data['tweets'] = $this->twitter->get_latest();
            //END of twitter section    
        
        if($this->template['profile'] = $this->profile->get($user))
        {
            $this->load->vars($this->template);
            $this->load->view('profile.php', $data);
        }
    }
Model:
Code:
class Profile_Model extends Model
{
    function Profile_Model()
    {
        parent::Model();
        $this->table = "users";
    }
    function get($user)
      {
         $this->db->where('username', $user);
         $query = $this->db->get($this->table, 1);
            if($query)
            {
                if($query->num_rows() == 1)
                {
                    return $query->row_array();    
                }    
                else
                {
                $data['error_msg'] = "The user <strong>".$this->uri->segment(1)."</strong>, does not exist! Please check your spelling.";
                $this->load->view('error', $data);        
                }
            }    
      }
    function twitter_info_public($user)
    {
        $this->db->where('username', $user); // Set the WHERE condition
        $query = $this->db->get($this->table, 1); // Return the result row
        return $query->row_array();
    }

The above code is untested.


Messages In This Thread
Using functions set in a model? [SOLVED] - by El Forum - 02-21-2009, 01:24 PM
Using functions set in a model? [SOLVED] - by El Forum - 02-21-2009, 01:59 PM
Using functions set in a model? [SOLVED] - by El Forum - 02-21-2009, 02:36 PM
Using functions set in a model? [SOLVED] - by El Forum - 02-21-2009, 02:47 PM
Using functions set in a model? [SOLVED] - by El Forum - 02-21-2009, 02:49 PM
Using functions set in a model? [SOLVED] - by El Forum - 02-21-2009, 02:51 PM
Using functions set in a model? [SOLVED] - by El Forum - 02-21-2009, 03:00 PM
Using functions set in a model? [SOLVED] - by El Forum - 02-21-2009, 06:58 PM
Using functions set in a model? [SOLVED] - by El Forum - 02-21-2009, 07:17 PM



Theme © iAndrew 2016 - Forum software by © MyBB