• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Beginner needs advice for (yet another) layout problem

#1
[eluser]oll[/eluser]
Hello all,

I'am developping a Youtube-like application for my work. The first version was done from scratch whith PHP Mysql but I try to make it work the same with CI.

I'm not a developper (only a poor admin ) , so excuse me in advance for the ugly code Wink

The application is quite simple. To simplify it, it has 3 components :

* a form for choosing the month/year/group (this is actually a more sophisticated search engine)
* a playlist that displays all links to choosen videos from the selected month/year/group
* a player that runs the video in a flash player, displays the description, shows comments and allow users to post new ones.

So I created a Videos controller in which I have these 3 functions. Here is a piece of code for illustrating it :

My controller :

Code:
<?php

class Videos extends Controller {

    function Videos()     {
        parent::Controller();
        //
        //   a lot of ugly functions I did
        //
    }
    
    function index()     {
        $this->gam(); //gam = form Groupe/Mois/Annee , ie Group/Month/Year
        
    }
    
    function gam () {
        $this->load->view('form_gam.php');
    }
    
        
    function createplaylist () {
        $choice = $this->remove_submit_from_post($_POST);
        //
        //   a lot of ugly code
        //
        $videos = $this->playlist->get_playlist($choice);
        //
        //   a lot of ugly code
        //
        $this->load->view('playlist_view',$videos);
    }
        
        
    function createplayer ($video_id) {
            //
            // a lot of ugly code
            //
            $data['url']=$this->playlist->get_url_by_id($video_id);
            $this->load->view('video_view',$data);
    }
}
            

?>

My views :

* form_gam :

Code:
<?php

echo form_open('videos/createplaylist');

$mois = array ('January'=>'January','February'=>'February','September'=>'September','October'=>'October');
$annee = array ('2008'=>'2008','2009'=>'2009');
$groupe = array ('tutorials'=>'Tutorials','comm'=>'Communication','public'=>'Public');


echo form_dropdown('groupe', $groupe);
echo form_dropdown('annee', $annee);
echo form_dropdown('mois', $mois);


echo form_submit('submit','ok');

echo form_close('')
?>


* playlist_view

Code:
<div id="right">
&lt;?php foreach($videos as $video): ?&gt;
        <a href="videos/createplayer/&lt;?=$video['id']?&gt;">
        // a lot of ugly code for displaying author, thumbnail, comments, etc

&lt;?php endforeach; ?&gt;
</div>

* player view (video_view)

Code:
<div id="left">
[removed]
    // place Flowplayer to our DIV
    flashembed("player", "&lt;?php echo base_url() ?&gt;flowplayer/FlowPlayer.swf", {config: {
        
    // Flowplayer configuration as comma separated list
    videoFile: '&lt;?php echo $url ?&gt;',
    initialScale: 'scale'
     //... more uninteresting
[removed]
<div id=player></div>
</div>

So all that works :

If I do a :
http://mysite.com/index.php/videos
I have the form.

If I choose a month/year/group, I have my playlist in another page.
If I click on one video from the playlist page, It opens me a new page whith the player.

(I tried to respect the MVC model)

But what I would like, is to have all that in the same page : the form in the top, the player to the left and the playlist to the right.

The problem is that I don't want my playlist to be reinitialized when I click on a video. (actually, the generated playlist depends on more choices (not only group/month/year but also tags, author, "search in description", etc...)

What I did to try to display everything in the same page is :

* change my playlist_view to a form pointing to my controller , instead of a elegant link to my createplayer function.

* Put a :
Code:
if (isset($_POST['video_id'])) {
$video_id = $_POST['video_id'])
} else {
$video_id=DEFAULT_VIDEO
}

and

Code:
$this->player($video_id);

in my index function.

But the problem is that my playlist is "reinitialized" since this creates a new instance of my controller.

It also can be technically solved, passing all the $choice element as hidden inputs in the former form, and adding all "if isset($POST .." in the index() function or constructor of my controller. But this is very ugly, no ?

Do you know if there an elegant way to do it ? (whenever possible without adding frames)
I spent hours goggling or reading the CI Wiki with no success. I think I read everything about Layout and embedded views , but I didn't find something speaking about how to change partial views contents without creating a new instance of a controller.
(in abstract, my player view needs to be changed , while my playlist view remains the same).

Thank you very much.

#2
[eluser]Dready[/eluser]
Hello and welcome to CI,

I see two ways of doing this :

* using "Ajax frame" (ajax to update a part of your DOM), just like deezer and others

* using a session object to store the current playlist for a user

#3
[eluser]oll[/eluser]
Thanx to the very great codeigniter user guide, I succeed in having what I wanted using sessions !
Thank you very much !


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.