Welcome Guest, Not a member yet? Register   Sign In
anchor error
#1

[eluser]learning_php[/eluser]
Hi,

I have been having trouble getting my links to work when i put my site live. it works on my localhost and everything i try does not seem to work. currently when i click a link it give a 404 error www.wesayido.co.uk. Here is my code:

config:
Code:
<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

/*
|--------------------------------------------------------------------------
| Base Site URL
|--------------------------------------------------------------------------
|
*/
$config['base_url']    = "http://www.wesayido.co.uk";
/*
|--------------------------------------------------------------------------
| Index File
|--------------------------------------------------------------------------
*/
$config['index_page'] = "";
/*
|--------------------------------------------------------------------------
| URI PROTOCOL
|--------------------------------------------------------------------------
*/
$config['uri_protocol']    = "PATH_INFO";

/*
|--------------------------------------------------------------------------

routes:
[code]
$route['default_controller'] = "Homepage";
$route['scaffolding_trigger'] = "";
$route['Info']="Homepage/Info";
$route['Gifts']="Homepage/Gifts";
$route['Gallery']="gallery/index";
$route['Church'] = "direction/direction";
$route['JockeyClub'] = "direction1/direction1";
$route['images'] = "Dashboard/index";

controller:
Code:
<?PHP

class Homepage extends Controller {
    
    function Homepage()
    {
    
    parent::Controller();
    $this->load->database();
    $this->load->helper(array('url', 'form', 'date', 'cookie'));
    $this->load->library(array('form_validation', 'upload', 'session','email'));
  
    
    }
    
    function Index()
    {
        
        session_start();
        $data['title']= "Hannah & Stephen's Wedding";
        $this->load->view('homepage_view', $data);
        
    }
    
    function Info()
    {
        $this->load->view('info_view');
    }


    function Gifts()
    {
        $this->load->view('gifts_view');
    }
    

    function register()
    {
    $this->load->view('register_view');    
    $this->db->get('pending_members');
    }
    
    function update_register()
    {

              $this->db->insert('pending_members',$_POST);
              redirect('index.php','Homepage');
              
    }
    
    function updatemembers()
    {
        
        $id = $_POST["id"];
        $approved = $_POST["approved"];
        $email = $_POST["email"];
        $this->email->from('[email protected]');
        $this->email->to($email);

        
        
        if($approved = "Yes") {
            $this->db->query("insert into members (select * from pending_members where id = " . $id . ")");
            $this->db->query("delete from pending_members where id = " . $id );
            
            
                $this->email->subject('Membership confirmed');
                 $this->email->message('Thank you for registering to view the Image Gallery.
                  Your membership has been confirmed and you can now access the Gallery.');
                $this->email->send();
            $this->load->view('update_data_view');
        
            
        }
        else if($approved = "No"){
            
            $this->db->query("delete from pending_members where id = " . $id );
            $this->load->view('update_data_view');
                $this->email->subject('Membership denied');
                $this->email->message('Unfortunately your membership request has been denied as you do not meet the full specifiction.
                Please contact us to resolve this problem, thank you.');
                $this->email->send();

        }
    }

            
            
        
}

?>

links in view:

Code:
<li>&lt;?= anchor('','Homepage');?&gt;</li>
    <li>&lt;?= anchor('/Info','Information');?&gt;</li>
    <li>&lt;?= anchor('/Gifts','Gifts');?&gt;</li>
    <li>&lt;?= anchor('gallery/index','Gallery');?&gt;</li>
If you can see my error please let me know
Thanks
#2

[eluser]tomcode[/eluser]
Did not read all Your code...

Your config base_url needs a trailing slash.

The anchor functions have no leading slash.

Which URL gives You the 404
?

EDIT : I did not use Your link Wink , Your 404's are server generated, Your .htaccess does not work.
#3

[eluser]Michael Nielsen[/eluser]
Thanks for getting married on my birthday - AWESOME!

Um try auto loading your helpers and libraries instead; if I remember correctly I was once told not to load them in that first function of the class.

Also try removing the leading space when you echo the links.

Example:

Code:
<li>&lt;?=anchor('','Homepage');?&gt;</li>

Not entirely sure if it's make a difference but often it's the little things.
#4

[eluser]learning_php[/eluser]
Hi,

i have changed the following:
I am now autoloading the libs and helpers also edited the code below
Code:
$config['base_url']    = "http://www.wesayido.co.uk/";

    <li>&lt;?=anchor('','Homepage');?&gt;</li>
    <li>&lt;?=anchor('Info','Information');?&gt;</li>
    <li>&lt;?=anchor('Gifts','Gifts');?&gt;</li>
    <li>&lt;?=anchor('gallery','Gallery');?&gt;</li>

also this is my .htaccess file i was not sure about this as the url's are being written corrrectly?
Code:
<IfModule mod_rewrite.c>
  RewriteEngine on
  RewriteBase /
  RewriteCond %{REQUEST_FILENAME} !-f
  RewriteCond %{REQUEST_FILENAME} !-d
  RewriteRule ^(.*)$ index.php/$1 [QSA,NC,L]
</IfModule>

<IfModule !mod_rewrite.c>
  # If we don’t have mod_rewrite installed, all 404’s
  # can be sent to index.php, and everything works as normal.

  ErrorDocument 404 /index.php
</IfModule>

Thanks

Also if you goto the full URL the page is there:
Code:
http://www.wesayido.co.uk/index.php/homepage/Gifts
#5

[eluser]TheFuzzy0ne[/eluser]
I'd suggest changing the URI protocol in your config.php to either QUERY_STRING or REQUEST_URI. Also, I'd suggest naming your controller methods in all lowercase, and calling on them in the same manner. I doubt this will make any noticeable difference, though.
#6

[eluser]learning_php[/eluser]
Hi,

I changed the controller to lowercase and the links now work!

Thanks I dont think i would have ever thought of that as i had matched the case in the controller and view.


Thanks again
#7

[eluser]TheFuzzy0ne[/eluser]
As far as I know, CodeIgniter converts the controller/method names to lowercase anyway, and I think that the method names might be case sensitive. I was under the impression that PHP was not case sensitive.




Theme © iAndrew 2016 - Forum software by © MyBB