[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>
<?php foreach ($query->result() as $row): ?>
<div class="bookmark">
<b><a >url;?>"><?=$row->title;?></a></b>
<p>Source: <?=$row->source;?></p>
</div>
<?php endforeach; ?>
</body>