Welcome Guest, Not a member yet? Register   Sign In
Loading views
#1

[eluser]Perkin5[/eluser]
I'm developing a blog and to handle the admin views I have a controller called blogadmin. From its index function it loads a multiple view like this:

Code:
$this->load->view('header_view');
$this->load->view('nav_view');
$this->load->view('blogadmin_view');
$this->load->view('footer_view');

and that works fine. In that view I have a small form with just a submit button called 'Create New Blog' and the action address is 'blogadmin/create_form'. create_form is a function that loads almost the same multiple view but now with a form view added like this:

Code:
$this->load->view('header_view');
$this->load->view('nav_view');
$this->load->view('blogadmin_view');
$this->load->view('blog_create_view');
$this->load->view('footer_view');

So when I click the button, the url changes to http://localhost/mysite/blogadmin/create_form as I would expect and I'm hoping to see a form spring into view but what happens is that all links to stylesheets, images and scripts are invalidated, destroying the look of the page.

I can't work out what I'm doing wrong. Can anyone give me a clue?
#2

[eluser]John_Betong_002[/eluser]
Here is a clueSmile

All CSS links are relative to the parent file.

Take a look at the URL to the CSS file that is working and compare with the URL to the file that is not working.

Many others posters have problems and usually hard-code the path:

Code:
<link type='text/css' href='/your-asset-files/style.caa' rel='stylesheet' />
 
 
#3

[eluser]mi6crazyheart[/eluser]
I feel, may be u r hard coding u'r paths. Better, use.. " base_url() " technique or can use "form_open()" when u need to deal with forms...


Ref:
http://ellislab.com/codeigniter/user-gui...elper.html
http://ellislab.com/codeigniter/user-gui...elper.html
#4

[eluser]InsiteFX[/eluser]
These are the different ways for css images js etc.
Code:
<base href="<?php echo base_url();?>">
<link type="text/css" rel="stylesheet" href="css/styles.css">

Or
Code:
<base href="<?php echo base_url();?>">

<link type="text/css" rel="stylesheet" href="<?php echo site_url();?>assets/css/styles.css">

<link type="text/css" rel="stylesheet" href="<?php echo base_url();?>assets/css/styles.css">

InsiteFX
#5

[eluser]Perkin5[/eluser]
Many thanks for these responses. The thing is that I'm using the form_open syntax that appears to give the correct path automatically. When I view source, the full path shows correctly in the code.
#6

[eluser]InsiteFX[/eluser]
And what does your
Code:
$this->load->view('blog_create_view');
look like?

InsiteFX
#7

[eluser]Perkin5[/eluser]
Well, it looks OK now because, as a workaround, I have produced separate controllers for each of the views. It was trying to load different views from the same controller that caused me trouble, neater though that would have been in coding terms.

The way I have it organized now is that you go to blog admin (via a login obviously) where you have three buttons that will take you to the create, update and delete controllers respectively, instead of my previous arrangement where they all went back to methods in the main blog controller. That seems to work perfectly and maybe that's the correct way to organize it anyway but I don't have the experience to know.

As a matter of interest, I get the same error by adding a trailing slash to any URL but that may be unconnected.

Was my original approach undoable?
#8

[eluser]danmontgomery[/eluser]
No.

The issue is either that you're trying to use relative paths to your assets, with a simulated file path in the browser, or you're putting assets somewhere in the application directory (probably with views), which is wrong. Or maybe both.

Your original approach is very doable, in fact overwhelmingly preferred to creating a separate controller for each view. You just should not be doing either of the two things above.
#9

[eluser]Perkin5[/eluser]
Thanks very much for that. I understand what you're saying so I'll sign off on this one and spend some time checking out the codeigniter url helper functions base_url, site_url etc.

Much appreciate your help.




Theme © iAndrew 2016 - Forum software by © MyBB