Welcome Guest, Not a member yet? Register   Sign In
Please help me coding static page
#1

[eluser]dhaulagiri[/eluser]
Hello guys.

I am building static site in CI, where I will have many pages from one controller. For example: welcome controller will serve following page:

welcome controller => home(), about_us(), contact_us() and services()

Now, I want couple of more controller like welcome and each controller showing it's own pages and give links in sidebar of web page ( just like submenu) how do i do it ?
#2

[eluser]mi6crazyheart[/eluser]
Can't understand u'r problem properly about of need more of controllers. What i mean to say, if u want more controllers then make as many as u want... who has stooped...
#3

[eluser]dhaulagiri[/eluser]
I want some way where I can generate side menu on different pages based on top menu of site ( which will be main menu) pls help. Thanks
#4

[eluser]pickupman[/eluser]
If it's not a lot of links, just hard code them in a view, and then have "different" pages view call the sidebar. One way to do this is name files in /views like sidebar_different.php for controller different.php. You can use uri segements like:
Code:
//In sidebar of view
$controller = $this->uri->segment(1,'welcome');
$this->load->view('sidebars/sidebar_'.$controller, $data);

If you have a lot of links, you will need to create a routine in your model, to fetch pages by a controller name, and build the links dynamically.
#5

[eluser]dhaulagiri[/eluser]
Did you mean I need to make another controller and view for that purpose ?
#6

[eluser]pickupman[/eluser]
[quote author="dhaulagiri" date="1277850791"]Did you mean I need to make another controller and view for that purpose ?[/quote]

You had mentioned you wanted to create another controller like the welcome controller that would use a sidebar/submenu. The code I posted above would load a sidebar view based on the controller name.
#7

[eluser]dhaulagiri[/eluser]
well can you pls explain how can i solve this with routing ? For the above problem did this in sidebar
Code:
<?php
if ($this->uri->segment(1) === 'welcome')
{
    echo 'lists for welcome';
    
}
elseif($this->uri->segment(1) === 'blog')
{
    echo ' lists for blog';
}
else
{
    echo 'please add links';
}
?>
#8

[eluser]pickupman[/eluser]
The routing feature is like mod_rewrite. It will automagically rewrite uri(s) on how they are written. In the context of your question, routes do not apply.

How/Where are you wanting to use routing?
#9

[eluser]Josh Bright[/eluser]
Hmm, if what your looking for is a way to have a few different controllers (each with their own methods/pages), and have a menu where you can navigate between all these things, I would just use a view.

Its actually much easier if you look into building a template system for Codeigniter. By doing this, you can really easily add a menu view to your site and have it on all your pages.

Here is how I accomplish this:

Example Controller
Code:
class Test_Controller extends Controller {
     public function index() {
          $data['main_content'] = "index_view";  //This will be my view file that gets loaded
          $this->load->view('template/template_view', $data); //My template view (more below)
     }
}

So, then in my views folder I have a template folder. In that folder is a few files, one of them being this template_view file. Here is a mockup of that file:

Code:
$this->load->view('template/html_header_view');
    
    if (isset($page_header)) {
        $this->load->view($page_header);
    }
    
    if (isset($navigation_content)) {
        $this->load->view($navigation_content);
    }
    
    $this->load->view($main_content);
    
    $this->load->view('template/footer_view');

So, as you can see here, the view I call, first calls a html_header_view file. This is pretty much everything from the start of the page, up to the opening body statement. After that I check to see if I have passed in a page_header view, which would be like the top part of the page with the website name and such.

I then check if I passed any data into a $navigation_content variable. If I did, I'll load that view file up next. This is where my menu resides.

I'll then load the view I passed as $main_content (that index_view file), and finally a footer_view file that wraps up my body tag and anything else I might want there.

Now, finally, my menu view looks something like:
Code:
<?php
    $menu = array(
        'Home'=>'main/index',
        'Upload File'=>'upload/index',
        'History'=>'history/index',
        'Preferences'=>'prefs/index',
        'Logout'=>'logout/index'
    );
    
    $uri_segment = $this->uri->segment('1');
    if ($uri_segment == "") {
        $uri_segment = "main";
    }
?>

<div id='site_menu'>
    <ul>
        &lt;?php
            foreach ($menu as $key=>$item) {

                $uri_parts = explode("/", $item);
                if ($uri_segment == $uri_parts['0']) {
                    echo "<li class='menu_selected'>";
                } else {
                    echo "<li class='menu_not_selected'>";
                }
                echo anchor($item, $key);
                echo "</li>";
                $uri_parts = "";
            }
        ?&gt;
    </ul>
</div>


So, you can see that I first have a $menu array. This a pretty simple way of doing this, but, it works just fine. The key to each item in the array is what would show up on the screen for the menu item, and the value is the url that will get put into the <a> tag.

After that menu array I get a variable setup to show my current controller im in (using that $this->uri->segment() method). If someone just goes right to my site without clicking any links, the default controller might not be shown, so, if the $uri_segment is empty I just tell it that its 'main' (my default controller from routes.php)

Below that I build the actual menu using that $menu array. I'll loop through the menu array, and the first thing I do is explode the url string, and grab the controller name from it. If the controller name from the array matches my current controller name, I wrap the <a> tag in an <li> tag with a class of menu_selected, if its not, the <li> tag has a menu_not_selected class.

So, there's really nothing that you need to do with routing, besides setting your default controller. There's really nothing that 'links' these controllers together or anything, just by building a list of links that point to your various controllers you'll end up with, I think, what your looking for.

Lemme know if im way off base or if this helps, or if you want me to explain something a bit more in depth.

Josh B




Theme © iAndrew 2016 - Forum software by © MyBB