Welcome Guest, Not a member yet? Register   Sign In
Codeigniter Arcade - Models and Controllers - Pulling Game ID from the URL
#1

[eluser]Devon Lambert[/eluser]
Hello Codeigniters,

Let me preface this post with the typical *I am a newbie* warning. That said, I am hoping that some gracious individual on these forums can get me started in the right direction with the conversion of my arcade script over to CI by breaking out the following example for me into exact code (i.e. split out the portions that belong in a model, controller, etc) and also include the functions/objects/methods involved?

Please please please:

So I have a model named mdl_game.php and a controller named game.php.


I need to build a function in the model that will do the work of pulling the "Game ID" from the "URL" and then pull the Game's information from the DB based on the ID and store the information in an array named $info (or whatever you want it to be named :-) ).

Then...

In the controller I would need to load in that model, and call it's function.

All of this work would hopefully allow me to eventually build the code that will display the flash games that I have on my site.

Any helpers?
#2

[eluser]gtech[/eluser]
my advice is to read the user guide general topics on controllers,models and views.

your controller function will have a parameter say $gameid and that gets passed to the model

eg
Code:
//controller function
..
  function getgame($gameid) {
    $this->load->model('mdl_game');
    $gameinfo = $this->mdl_game->getgamedb($gameid);
    //game info will be an associative array containing the row information
    //as load view expects an associative array it should split the array into
    //variables relating to the column names in the db table
    $this->load->view('whatever',$gameinfo);
  }
..
//model function
..
  function getgamedb($gameid) {
    $result = $this->db->getWhere('games',array('gameid'=>$gameid));
    // will return array('gameid'=>5, '<column>'=>'<data>') etc.
    return $result->row_array();
  }
..
//view
&lt;?=$gameid?&gt;<br>
&lt;?=$column_name1?&gt;<br>
&lt;?=$column_name2?&gt;<br>

The URL would look somthing like
http://<CIINSTALL>/index.php/game/getgame/5
5 begin the game id.

I have not tested this code, its there to give you an idea along with reading the guide

hope it helps.
#3

[eluser]Devon Lambert[/eluser]
Thanks for that gtech.

I have been studying the guide but it leaves you hanging in some areas.

I actually found the forums much more useful once I began searching.

Thanks again. :-)




Theme © iAndrew 2016 - Forum software by © MyBB