views:

189

answers:

3

Hi,

Im trying to learn the code igniter library and object oriented php in general and have a question.

Ok so Ive gotten as far as making a page which loads all of the rows from my database and in there, Im echoing an anchor tag which is a link to the following structure.

[code]echo anchor("videos/video/$row->video_id", $row->video_title);[/code]

So, I have a class called Videos which extends the controller, within that class there is index and video, which is being called correctly (when you click on the video title, it sends you to videos/video/5 for example, 5 being the primary key of the table im working with.

So basically all Im trying to do is pass that 5 back to the controller, and then have the particular video page output the particular rows data from the videos table. My function in my controller for video looks like this -

[code]
function video() { $data['main_content'] = 'video'; $data['video_title'] = 'test'; $this->load->view('includes/template', $data);
} [/code]

So ya, basically test should be instead of test, a returned value of a query which says get in the table "videos", the row with the video_id of "5", and make $data['video_title'] = value of video_title in database...

Should have this figured out by now but dont, any help would be appreciated!

A: 

What you need is to understand how the URI Class works

Basically:

$default_url_args = array('video');
$url_args = $this->uri->uri_to_assoc(3,$default_url_args);
$video_UID = $url_args['video'];

and then something like

$the_video = $this->videos_model->get_video_by_UID($video_UID);
Iraklis
A: 

You could use the URI Class, or you can do the following:

function video($video_id)
{
  $data['main_content'] = $this->videoprovider->get_video( $video_id );
  $data['video_title'] = 'test';
  $this->load->view('includes/template', $data);
} 

In other words, with functions inside classes that extend Controller, you can add parameters to those functions and CI will automatically pass in the URI items in order to those parameters.

function generic_function_in_controller($item1, $item2, ...)
{
  // would receive as: http://example.com/controller/generic_function_in_controller/item1/item2
}
Kurucu
A: 
rabidmachine9