Welcome Guest, Not a member yet? Register   Sign In
How would I go about creating a persistent header in CI?
#1

[eluser]_just_me[/eluser]
Hi All,

I'm quite new to both PHP and CI and so far am overwhelmed and endeared by the amazingly helpful community that both have. Therefore I'm hoping to gain some insight into a problem that will presenting itself to me very shortly...

I've just started building an application and wrestled for a few short buy enjoyable hours integrating the ion_auth framework (kindof successfully), and now stuck with where to go with my next issue. I intend for users to play music files on site, but instead of directly in page or as a popup window, I'd like to use the header section to accept the chosen file, display some of its details along with a player and be persistent site wide.

For example, a user sees a track listed on the homepage, wants to play it, clicks play and asynchronously it is positioned and begins playing in the header. Now the user wishes to go to the forums so they click the forums link from the navigation and are taken there, but I don't wish for a page reload as this will stop the track that is playing, so this is where I'm stuck.

The typical load view section of a controller of mine looks as below (which I understand to be fairly standard :

$this->load->view('inc_header');
$this->load->view('home',$data);
$this->load->view('inc_footer');

Could anyone shed some light on how I ought to be going about this in CI?

I'd love any help.

Wow, quite an essay - I apologise, though wished to express my issue in full detail.
Cheers,
Matt
#2

[eluser]Madmartigan1[/eluser]
My first few websites were music sites, and I had to do this. Have a look at some examples. (Warning: Music will play automatically)

http://curtramm.com/
http://loukoumband.com/

The sites were small enough that I could just load every page with AJAX. If your site won't be able to hang with that, these are the other options I can think of:

1. Frames (yuck)
2. Load the main content in an iframe, have the player and header/footer outside the iframe.
2. All flash site (yuck)
3. Use a small popup window to play the music, outside of the parent document. You can probably figure out how to control the player from the parent window.

Can't think of any others.

There is nothing in Codeigniter that will help, as this is not that kind of issue, if you take my meaning. Let me know if you need some tips on implementing any of these techniques.

Good Luck!
#3

[eluser]_just_me[/eluser]
Thanks for the reply Madmartigan1.

I had a look at your sites and they're the sort of thing I'm looking for in terms of display. Though with the complexity of the pages, it's really not something I'd be able to use with AJAX I don't think.

From your suggested options I think the content as an iframe seems the most feasible/friendly option, although I did stumble across this template structure for CI http://williamsconcepts.com/ci/codeignit...index.html - from what I can understand, it seems like I would be able to define regions to load. Therefore I assume that the header would be persistent and just the content, sidebar / whatever I chose, would be refreshed with content. Unless I'm mis-understanding.

Thanks very much for your input!

Cheers,
Matt
#4

[eluser]SecretAgentX9[/eluser]
n/m.
#5

[eluser]CroNiX[/eluser]
Just make a helper function so all you have to do is pass the main view and data array.
I created a much more elaborate library which gets autoloaded, but this will work for something simple.

just save this in helpers as "assemble_view_helper.php".
Then load it by $this->load->helper('assemble_view'); or just autoload it.
Code:
function assemble_view($content_view, $data = array())
{
    $CI =& get_instance();
    $CI->load->view('inc_header');
    $CI->load->view($content_view, $data);
    $CI->load->view('inc_footer');
}

Then instead of doing
Code:
$this->load->view('inc_header');
$this->load->view('home',$data);
$this->load->view('inc_footer');
You would just
Code:
assemble_view('home', $data);
#6

[eluser]CroNiX[/eluser]
nevermind, this has nothing to do with what you were asking. I'm too tired... Smile Sorry.
#7

[eluser]n0xie[/eluser]
[quote author="_just_me" date="1293997709"]Thanks for the reply Madmartigan1.

I had a look at your sites and they're the sort of thing I'm looking for in terms of display. Though with the complexity of the pages, it's really not something I'd be able to use with AJAX I don't think.

From your suggested options I think the content as an iframe seems the most feasible/friendly option, although I did stumble across this template structure for CI http://williamsconcepts.com/ci/codeignit...index.html - from what I can understand, it seems like I would be able to define regions to load. Therefore I assume that the header would be persistent and just the content, sidebar / whatever I chose, would be refreshed with content. Unless I'm mis-understanding.

Thanks very much for your input!

Cheers,
Matt[/quote]
The template library will help you define regions but won't let your player 'persist'. If you want to refresh only certain parts of your page, you are pretty much stuck with AJAX or Iframes...
#8

[eluser]_just_me[/eluser]
CroNiX - Heh, no worries, I'm in a fairly persistent zombie state myself so know what it's like!


n0xie - Yeah, I've discovered this after playing around with the templates. I got the occasional feeling where I have done exactly what I need to, only for reality to bite and then back to square one!

So going down either the iframe or AJAX route; if I were to build the site as a standard CI application only playing the media files as a pop out window, rather than integrated, how difficult would it be to convert to an integrated and persistent header down the road? Would it be a complete rebuild?

Cheers,
Matt




Theme © iAndrew 2016 - Forum software by © MyBB