[eluser]brainer[/eluser]
Hi there,
I'm a bit of a newbie, who's trying to convert my entire procedural php website to a codeigniter based site.
But I've hit a bit of a problem early on, I'm sure its really simple enough, but im just not that used to working with an mvc pattern.
The thing is, im not sure where or how to modify my db results before i send it on to the view. At the moment this is what im doing...
The model
Code:
class Home_model extends Model
{
function getLatestProjects()
{
$query = "SELECT DISTINCT projects.name, projects.projectnameid, dudes.usernameid, dudes.username, folders.foldernameid, projects.url
FROM projects
INNER JOIN dudes
ON projects.userid = dudes.userid
INNER JOIN folders
ON projects.folderid = folders.folderid
INNER JOIN pieces
ON projects.projectid = pieces.projectid WHERE projects.published = 1 ORDER BY projects.date DESC LIMIT 40";
$q = $this->db->query($query);
if ($q->num_rows() > 0){
foreach ($q->result() as $row)
{
$data[] = $row;
}
return $data;
}
}
}
the controller
Code:
class Home extends Controller
{
function Home()
{
parent::Controller();
}
function index()
{
$this->load->model('home_model');
$data['records'] = $this->home_model->getLatestProjects();
$this->load->view('home_view', $data);
}
}
the view
Code:
<?php foreach ($records as $row) :?>
<div class="box" title="<?=$row->name?> by <?=$row->username?>">
<a >usernameid?>/<?=$row->foldernameid?>/<?=$row->projectnameid?>">
<img >url?>_thumb_s.jpg" alt="<?=$row->name?> by <?=$row->username?>">
</a>
</div>
<?php endforeach; ?>
The issue is, the "$row->url" needs to have the extension taken off, which i used to do during the loop in my old procedural script, but here, i dont know how to do it with my current structure.
...sorry for the massive post