Welcome Guest, Not a member yet? Register   Sign In
Passing Arguments from View to Controller?
#1

[eluser]Unknown[/eluser]
I'm completely new to CI and I have recently hit a road block. I'm very unsure how I would go about passing a function argument from the view file to the controller so I could use it on a function?

I have a foreach loop on the view going through the all the items passed by function get_latest_bookmarks. That function returns a ID for each item and I am wanting to use this with another function called get_bookmark_tags which will get the tags of the bookmark from another table. I have provided the code I have done so far below.

Model:

Code:
class Bookmarks extends CI_Model {

    function __construct()
    {
        parent::__construct();
    }
    
    // GET LATEST BOOKMARKS
    
    function get_latest_bookmarks($limit)
    {
        $this->load->database();
        $this->db->order_by("id", "desc");
        $query = $this->db->get('site', $limit);
        return $query;
    }
    
    // GET HOTTEST BOOKMARKS
    
    function get_hottest_bookmarks($limit)
    {
        $this->load->database();
    }
    
    // GET BOOKMARK TAGS
    
    function get_bookmark_tags($id)
    {
        $this->load->database();
    }

}

Controller:

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {

    public function index()
    {
        // Load Model
        $this->load->model('Bookmarks');
        // Get Latest Bookmarks
        $data['query'] = $this->Bookmarks->get_latest_bookmarks(4);
        // Load and Pass Data into View
        $this->load->view('welcome_message', $data);
    }
}

View:

Code:
<body>

<h1>Hot Bookmarks</h1>

<p>The most popular bookmarks will appear here.</p>

<h1>Latest Bookmarks</h1>

&lt;?php foreach ($query->result() as $row): ?&gt;

<div class="bookmark">
    <b><a >url;?&gt;">&lt;?=$row->title;?&gt;</a></b>
    <p>Source: &lt;?=$row->source;?&gt;</p>
</div>

&lt;?php endforeach; ?&gt;

&lt;/body&gt;


Messages In This Thread
Passing Arguments from View to Controller? - by El Forum - 06-10-2011, 06:41 PM
Passing Arguments from View to Controller? - by El Forum - 06-10-2011, 11:21 PM
Passing Arguments from View to Controller? - by El Forum - 06-10-2011, 11:41 PM



Theme © iAndrew 2016 - Forum software by © MyBB