Welcome Guest, Not a member yet? Register   Sign In
Image display and routes.php or controller??
#1

(This post was last modified: 11-12-2014, 01:42 AM by discofunk.)

I am using CodeIgniter 2.2.0 for the first time to create a multilingual site where the home page contains a slide show. I am developing it on my laptop -
Code:
localhost/website/

I am using the routes.php file to specify which language function to call to set variables depending on the url with format

Code:
http://localhost/website/language/page_id/some-page-title


Thus
Code:
http://localhost/website/en/1/Home-Page
gives the english page of page_id 1.

Routes file therefore has:

PHP Code:
$route['default_controller'] = "content";
$route['en/(:num)/(:any)'] = "content/en/$1";
$route['de/(:num)/(:any)'] = "content/de/$1";
$route['es/(:num)/(:any)'] = "content/es/$1"
etc
An example of a language function (the en function) in the content controller is:

PHP Code:
public function en ($page_id) {
        
$lang_array['language']="en";
        
$lang_array['css']="base.css";
        
$this->get_content($page_id$lang_array);


The get_content function then does everything.

The index function of the content controller however looks like this:

PHP Code:
public function index() {
            
//setting defaults for when arrive straight at home page or with no language in url
            
$page_id=1;
            
$lang_array['language']="en";
            
$lang_array['css']="base.css";
            
$this->get_content($page_id$language);
        } 
My problem is that when I go to

Code:
http;//localhost/website/

everything works fine including the slideshow. However, when i go to the url
Code:
http://localhost/website/en/1/Home-Page
everything works EXCEPT the pictures in the slideshow and content part of page don't appear (even though they are both executing the same code and the html output is the same when i look at view source on the page).

The only thing i could think of is the fact that if i just put http;//localhost/website/ then the index function will be called which activates the constructor, but if i put http://localhost/website/en/1/Home-Page then the index and thus constructor are bypassed. However dont know why therefore other things still work but pic slideshow doesn’t. Is this the reason do you think? any solutions?

Thanks

TOm



The thing that is really freaking me out is that the outputted code from both urls (simple root url and url with language components) is EXACTLY the same.

The links to images etc are both exactly same and also use base_url() to get around path issues. So confused. How can two identical pieces of html display different results?




On a different forum, someone has suggested it has to do with the images not being passed through the routes.php file due to the .htaccess...is this true and can anyone help with what code i need to let this happen as .htaccess is not my strong suit...

many thanks

Tom
Reply
#2

Can you copy the images paths in both cases (which are generated in your browser)?

Its good to use base_url() . '/img/path' for such static files ..
Best VPS Hosting : Digital Ocean
Reply
#3

(This post was last modified: 11-14-2014, 08:13 AM by Chroma.)

(11-12-2014, 02:09 AM)sv3tli0 Wrote: Can you copy the images paths in both cases (which are generated in your browser)?

Its good to use base_url() . '/img/path' for such static files ..

I have always found it better from a maintainability perspective to put the path inside the base_url() function:

base_url('/img/path')

(11-12-2014, 01:39 AM)discofunk Wrote: Thus
Code:
http://localhost/website/en/1/Home-Page
gives the english page of page_id 1.

Routes file therefore has:

PHP Code:
$route['default_controller'] = "content";
$route['en/(:num)/(:any)'] = "content/en/$1";
$route['de/(:num)/(:any)'] = "content/de/$1";
$route['es/(:num)/(:any)'] = "content/es/$1"
etc

I don't know how your program is supposed to work, but I do notice, that you are disposing of anything in the route apart from the number.

You are not using $2 which is the (:any) part of the route.

Is this a deliberate part of your system or do you need the remainder?
Reply




Theme © iAndrew 2016 - Forum software by © MyBB