Welcome Guest, Not a member yet? Register   Sign In
[SOLVED] view loader, right page wrong url
#1

[eluser]Brandt1981[/eluser]
When i use the view loader it sends me to the right place but the url in the address bar stays the same, and my images aren't showing up for some reason.

for example:

my starting url is: home

i submit some form data to home/query

The url becomes: home/query

The query function ends with this: $this->load->view('home', $vars);

The url is still: home/query

Also my images are not showing up anymore at this point, and I want the url to go back to just 'home'


Any ideas?
#2

[eluser]tonanbarbarian[/eluser]
not really sure what the main issue is that you are going on about

the fact that you images are not loading is probably due to using relative paths for the images rather than absolute
i.e. use
Code:
<img src="http://somewhere.com/images/home.png" />
rather than
Code:
<img src="../images/home.png" />
#3

[eluser]Brandt1981[/eluser]
Thank you, that wasn't really obvious to me at first as I wasn't changing the page I was on, although
the view loader was changing the URL from 'home' to 'home/query'


I changed it to this:

Code:
<img src="&lt;?php echo base_url().'images/elite_logo.png'; ?&gt;" height="75px" style="margin: 2px 0px 0px 2px;">
#4

[eluser]tonanbarbarian[/eluser]
it is the form submit which is changing the url, not CI directly.
#5

[eluser]Brandt1981[/eluser]
hmm it just feels like the url should not change if i'm still on the same page, just basically doing a function call...is there a way to call a function in the controller without changing the url in a submit?
#6

[eluser]bretticus[/eluser]
[quote author="Brandt1981" date="1287473177"]hmm it just feels like the url should not change if i'm still on the same page, just basically doing a function call...is there a way to call a function in the controller without changing the url in a submit?[/quote]

Your problem is just that you are not understanding the differences between client-side and server-side. This is a very important concept in Web development and a basic core principal (that many new Web developers need some time to wrap their heads around as did I about 11 years ago.) From the client-side perspective, the very first / after the URL is the "root" of the file system. It's common (and not a PHP problem much less a CodeIniter problem) to stipulate the absolute path in your html documents (your views in this case.) That means if you have an images folder (a real one) parallel to your index.php file, the full path to images in your html document is /images/. ie. use <img src='/images/somepic.png'/>. Including the full URL is okay too (as you are doing) but not necessary.

CodeIngniter is a web framework that uses "segments" to route client requests (your browser points to a URL.) Segments are analogous to folders or directories. http://url.tld/home/query literally tells the Web server to look for the query folder in the home folder of the root (or virtual root as it is called.) Most Web servers will take a folder path with no file specified to be index.html or index.php if they exist. Many years ago, people discovered they could emulate this folder structure to tell the script what content to show. In other words, query/home does not refer to a folder in a folder in the virtual root. CodeIgniter makes use of Apache's mod rewrite (in most cases) to send all requests to the index.php page. CodeIgniter, through it's routing object, determines which controller function (called methods in classes) you run based on that URL. One advantage is that this folder structure works well for search engine indexing and is much friendlier for real people (because we understand hierarchical structure better than long GET string with pairs of keys and values.)

My point is that you are assuming that the relative paths for the html content are relative to the URL. In CodeIgniter's case, they are not! No doubt, it's a strange change in mindset for a person who may have worked previously with static webpages or non-MVC Web development.

Finally, with all that in mind, to answer your question. Which URL the form posts to and the paths inside the html document (view) have absolutely nothing to do with each other. Make sure you use absolute paths (ie. /images/... or &lt;?=base_url()?&gt;images/...)
#7

[eluser]Brandt1981[/eluser]
Thanks, I am a solaris unix sys admin by day, and a computer science student by night, so I am able to follow all of this just fine. Just not used to OOP or MVC type programming. More used to procedural programming such as shell scripting Smile
#8

[eluser]bretticus[/eluser]
I am also a unix sys admin and happen to be a Web Developer as I work for a Web company. I had always wished that that I had gotten a CS education with my IT education, so that's awesome. I had to learn on my own. Your questions just show you are new to Web development, that's all. They were meant to be thorough and not to insult your intelligence. Had I known your background, I could have answered your question by just saying, "Since CodeIgniter is a 'segment-based' framework, the controller/method URI schema requires that you use absolute paths in your view HTML." Have fun!




Theme © iAndrew 2016 - Forum software by © MyBB