1
votes

I am a little confused. The following is my nav controller. i have been getting my page layout this way.

nav

    <a href ="<?php echo base_url();?>main/index/home_v">Home</a>
    <a href ="<?php echo base_url();?>main/index/contact_v">Contact</a>
    <a href ="<?php echo base_url();?>main/index/test_v">Test</a>    

Main Controller

public function index()
{ 
    if($this->uri->segment(3))
    {
        $content = $this->uri->segment(3);
    }
    else
    {
        $content = 'home_v';
    }

    $data = ['title'=> 'home', 'main_content' => "$content"];
    $this->load->view('tempelate',$data);
}

since, all those content in my nav is inside view, its not a problem but what if i have a folder inside a view and want to send it to that controller? am i here all clear asking the question? because i am myself confused.

I want to sent another uri->segment into the same function.

<a href ="<?php echo base_url();?>main/index/category_v/category">Cat</a>

category here is the folder name. so now what i basically want to add into the function is .

$folderName = $this->uri->segment(4);
1
if you have a folder inside the view folder, and want to pass the $data to the view inside that folder, you can simply do $this->load->view('foldername/viewname', $data); - Parag Tyagi
@ParagTyagi-morpheus- my view name actually goes to the variable $content. now i have to add up a view name which is inside a folder. - umanga shrestha
some more code may help. - Parag Tyagi
i've added something more. @ParagTyagi-morpheus- - umanga shrestha
Its like the folder name is category and the view name inside it is category_v.php. Am I going right ?? - Parag Tyagi

1 Answers

0
votes

Didn't understood much from the question.
But still if you have a folder inside the view folder, and want to pass the $data to the view inside that folder, you can simply do,

$this->load->view('foldername/viewname', $data); 

EDIT:

public function index()
{ 
    $content = 'home_v';
    if($this->uri->segment(3))
    {
        $content = $this->uri->segment(3);
    }

    $foldername = '';
    if($this->uri->segment(4))
    {
        $foldername = $this->uri->segment(4).'/';
    }

    $data = ['title'=> 'home', 'main_content' => "$content"];
    $this->load->view($foldername.$content, $data);
}