• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Cannot normally load different content in one view.

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:
public function index($ilinkId)
    $data['content'] = $ilinkId;
    $this->load->view('front/vcontent', $data);

view vcontent:
if ($content == NULL)
       $content = "vgreeting";
require "content/".$content.".php ";

view vleftmenu:
<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):
| |_a lot of
| |_ style.css
| |_controllers
| | |_front
| | |_cmain.php
| |_view
| | |_front
| | |_vcontent.php ...etc

thank you in advance!

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

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


In your view file
[quote author="dimaomni" date="1309450263"]
if ($content == NULL)
       $content = "vgreeting";
require "content/".$content.".php ";
You should change
require "content/".$content.".php ";
require "application/view/front/content/{$content}.php";
// $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.
&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.

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2020 MyBB Group.