CodeIgniter Forums

Full Version: Cannot normally load different content in one view.
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]dimaomni[/eluser]
Hi all,

In general:
I have three column site. Each column is located in own view. Left column has menu. I want to display different content in middle column when I click on links.

What is best practice for this task?


I try do it by 2 ways:
- Send via GET view's file name and insert this value to $this->load->view($contentName);
and it worked, however displayed page were incorrect displayed.

- then I tried in middle column(separate view) to use require "". and nothing change as for me.

controller cmain:
Code:
public function index($ilinkId)
  {
    
    $data['content'] = $ilinkId;
    $this->load->view('front/vheader');
    $this->load->view('front/vcontent', $data);
    $this->load->view('front/vleftmenu');
    $this->load->view('front/vrightmenu');
    $this->load->view('front/vfooter');

view vcontent:
Code:
<?php
if ($content == NULL)
    {
       $content = "vgreeting";
    }                          
require "content/".$content.".php ";
?>

view vleftmenu:
Code:
<li>&lt;?php echo anchor('front/cmain/index/vabout', 'About');?&gt;</li>

Now it seems that css doesn't load when I click on the link. Why ???

file structure(short):
/site
|
|_images
| |_a lot of
|-style
| |_ style.css
|
|__application
| |_controllers
| | |_front
| | |_cmain.php
| |_view
| | |_front
| | |_vcontent.php ...etc
|_index.php


thank you in advance!

El Forum

[eluser]dimaomni[/eluser]
in firebug I changed path from style/main.css to /../style/main.css ant it works! But why style/main.css works only for site but not for http://site/index.php/front/cmain/index/vabout ? and etc...


I changed path to css /../style/main.css and everything's work ok.

So I have 2 question: about path..
And about best practice.

Thanks! Smile

El Forum

[eluser]InsiteFX[/eluser]
Code:
&lt;base href="&lt;?php echo base_url();?&gt;"&gt;
&lt;link type="text/css" rel="stylesheet" href="style/main.css"&gt;

InsiteFX

El Forum

[eluser]CodeIgniteMe[/eluser]
In your view file
[quote author="dimaomni" date="1309450263"]
Code:
&lt;?php
if ($content == NULL)
    {
       $content = "vgreeting";
    }                          
require "content/".$content.".php ";
?&gt;
[/quote]
You should change
Code:
require "content/".$content.".php ";
to
Code:
require "application/view/front/content/{$content}.php";
or
Code:
$this->load->view("front/content/$content");
// $content is parsed first and returns the string value. Notice I used "" instead of ''
// You do not need to include ".php" extension because CI automatically does it for you.
In CI, everything is included/required from the index.php files and not from the view files themselves. This is done in the Server-side.

When you include CSS files in your browser, you are then doing a Client-side include, which should start from the base path of your site. Try this.
Code:
&lt;link href="&lt;?=base_url()?&gt;"style/style.css rel="stylesheet" /&gt;
Remember to enable short_open_tags if you want this PHP syntax.