Welcome Guest, Not a member yet? Register   Sign In
404 Not Found - sure it's simple but can't figure it out
#1

[eluser]gypmaster[/eluser]
Hi,

CI Newb and trying to follow a book on developing CI applications. Going ok except I keep getting a 404 Not Found Error, specifically:

The requested URL /ci/welcome/cat/7 was not found on this server.

when trying to access a function called 'cat' in the welcome controller.
I have a link from the 'home' page to the /ci/welcome/cat/7 url .. the link looks fine and should work. I have a controllers called cat in the welcome controller - here's some of the code in the controller.
Code:
<?php

class Welcome extends Controller {

    function Welcome()
    {
        parent::Controller();    
    }
    
  function index()
      {    
        $data['title'] = "Welcome to Claudia's Kids";
        $data['navlist'] = $this->MCats->getCategoriesNav();
        $data['mainf'] = $this->MProducts->getMainFeature();
        $skip = $data['mainf']['id'];
        $data['sidef'] = $this->MProducts->getRandomProducts(3,$skip);
        $data['main'] = 'home';
        $this->load->vars($data);
        $this->load->view('template');
      }
      
  function cat($id)
    {
        $cat = $this->MCats->getCategory($id);
        if (!count($cat))
            {
                redirect('welcome/index','refresh');
            }
        if ($cat['parentid'] < 1)
            {
                //show other categories
                $data['listing'] = $this->MCats->getSubCategories($id);
                $data['level'] = 1;
            }
        else
            {
                //show products
                $data['listing'] = $this->MProducts->getProductsByCategory($id);
                $data['level'] = 2;
            }
        $data['title'] = "Claudia's Kids | ". $cat['name'];
        $data['navlist'] = $this->MCats->getCategoriesNav();
        $data['category'] = $cat;
        $data['main'] = 'category';
        $this->load->vars($data);
        $this->load->view('template');
    }
I have set the default controller to 'welcome'.

Here's my .htaccess:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|captcha|css|js|robots\.txt)
RewriteRule ^(.*)$ /index.php/$1 [L]

anyone help with this?
TIA
#2

[eluser]wabu[/eluser]
I'm wondering about the directory "ci"--could there be some confusion about where everything's located?
#3

[eluser]gypmaster[/eluser]
Hi wabu,

Here's what I've got in my config.php file:
Code:
$config['base_url']    = "http://localhost/ci/";
#4

[eluser]wabu[/eluser]
Does everything live in "ci"? How about taking the "ci" out of your link (since that's "home")?
#5

[eluser]Chad Fulton[/eluser]
It's your .htaccess which is wrong, I think.

Your RewriteRule has /index.php/$1, which makes it look in your base directory (http://localhost/) for the index.php file, which I suppose is not there. Remove the first / to make it look in the current directory rather than the document root.

You can do:

Code:
RewriteEngine on
RewriteCond $1 !^(index\.php|images|captcha|css|js|robots\.txt)
RewriteRule ^(.*)$ index.php/$1 [L]
#6

[eluser]gypmaster[/eluser]
Everything 'lives' under "ci"

For example:

ci\system\application\controllers is the full path to the controllers folder

I changed the .htaccess but it made no difference.

Here's how the link is built in the code:

Code:
echo anchor("welcome/cat/$id",$name);

any other ideas?
thanks
#7

[eluser]wabu[/eluser]
Does the index function in your welcome controller work? Is it just cat that isn't working? [Cats have an unfortunate reputation as being lazy.]

Does .htaccess live in "ci" too, or your site root?
#8

[eluser]gypmaster[/eluser]
Hi,

lol,

cats are very lazy ... except when depositing in my garden Smile

seriously though, the index function does work just fine.

.htaccess lives in "ci", should it be somewhere else?

Cheers.
#9

[eluser]wabu[/eluser]
Okay, another try:

If you paste the following directly into your browser address bar, does it work?

http://localhost/ci/welcome/index/

If so, does pasting this one directly into your browser work?

http://localhost/ci/welcome/cat/5

You might have tried this already--I'm just trying to cover all the bases here. Wink

[Also you might simplify cat() to just "echo $id;" or something until it works.]
#10

[eluser]gypmaster[/eluser]
[quote author="wabu" date="1249516802"]Okay, another try:

If you paste the following directly into your browser address bar, does it work?

http://localhost/ci/welcome/index/

If so, does pasting this one directly into your browser work?

http://localhost/ci/welcome/cat/5

You might have tried this already--I'm just trying to cover all the bases here. Wink

[Also you might simplify cat() to just "echo $id;" or something until it works.][/quote]

I'd tried simplifying the cat controller but hadn't tried directly trying to reference the controller via the browesr address bar ... so I tried that and it didn't work. I typed

http://localhost/ci/welcome/index/

in the address bar

and get the 404 Not Found screen.

thanks for perseverance!




Theme © iAndrew 2016 - Forum software by © MyBB