Welcome Guest, Not a member yet? Register   Sign In
how to incorporate header and footer into views?
#1

[eluser]webdevguy32[/eluser]
I've completed the static page tutorial and have moved on to other tutorials using a "main" controller.

How do I incorporate a header and footer, like in the static page tutorial, into any other view called from a different controller?

Also, the header and footer will always be the same. The stuff in between is what I want to work with using the MVC. For example, there will be different menus based on your role. There will initially be a login screen, then a members page whose menu is based on your role. BUT, the header and foot will always be the same.

Also, if you have any links to talk about a CI way of handling role-based menus, please throw them up on the comments also.

Many thanks!
#2

[eluser]Storyteller[/eluser]
Well, the role based stuff is really dependent on what authentication/authorization system you are using. Generally a simple if statement does the trick.

In A3M, which I'm using, it is like this:
Code:
if($this->authorization->is_role('user'))
{
  //show user content
}

if($this->authorization->is_admin())
{
  //show administration links
}

Or in A3M you should probably use permissions for this.
Code:
if($this->authorization->is_permitted('user_management'))
{
  //show link to user management
}

As for headers and footers being loaded on each page there are different options. It goes simple as putting the code into their separate view files and then calling them on each page.
Code:
$this->load->view('haeder');

//the rest of the page

$this->load->view('footer');

To extending the controllers. My personally favorite approach is to build a template view with the header and footer in there and then echo $content variable somewhere and in controller you do this:
Code:
//get the homepage content
$data['content'] = $this->load->view('homepage', $data, TRUE);

//send the homepage content to the template and display
$this->load->view('template', $data);
The good thing about my last approach that you can specify additional data, like title and pass them to the header with ease.

Hope it helps.
#3

[eluser]webdevguy32[/eluser]
Most, most helpful. Many thanks.

What is A3M?

Does CI have a built-in login system I need to learn? I was using a tutorial's system which looked good but if CI has one built-in, I'd much prefer that.

Thanks again.
#4

[eluser]webdevguy32[/eluser]
So, with your code below, I would create a controller called "authorization" and it would have the medthods, is_role(variable=role_tpe) and is_admin, right?

Code:
if($this->authorization->is_role('user'))
{
  //show user content
}

if($this->authorization->is_admin())
{
  //show administration links
}
#5

[eluser]Storyteller[/eluser]
Yes. CI doesn't have build in authentication and authorization . There are multiple options which you can choose from.

Here are the two that I know of being very good:

A3M (which I'm using, I choose it for its social media integration):
https://github.com/donjakobo/A3M

Ion Auth (popular choice for many, has tutorials)
https://github.com/benedmunds/CodeIgniter-Ion-Auth

Or you can always make your own.
#6

[eluser]webdevguy32[/eluser]
Thanks, storyteller. I saw that A3M has not been updated in several years. Does that concern you?
#7

[eluser]Storyteller[/eluser]
[quote author="webdevguy32" date="1382296190"]Thanks, storyteller. I saw that A3M has not been updated in several years. Does that concern you?[/quote]
Depends on what branch you are looking. There was a lot of activity over summer where admin panel was added and many fixes and updates were made. I'm also currently working on the CI3 branch.
#8

[eluser]webdevguy32[/eluser]
Thanks. You are working on, developing, CI3, or are working with it? If working on, I read where eliaslabs are giving it up, or looking for someone to take it over. Is that you and others?
#9

[eluser]Storyteller[/eluser]
[quote author="webdevguy32" date="1382299795"]Thanks. You are working on, developing, CI3, or are working with it? If working on, I read where eliaslabs are giving it up, or looking for someone to take it over. Is that you and others?[/quote]
I'm working on A3M adaptation for CI3. To CI3 I have only contributed so far two user guide fixes. That being said, Ellis Lab is looking for someone to pick it up and manage it.




Theme © iAndrew 2016 - Forum software by © MyBB