0
votes

I just installed CodeIgniter 2.1.4. I want to call several functions in a controller. I have the following code:

Controller galeria.php:

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

class Galeria extends CI_Controller {


public function index() 
{
    $this->load->view('vgaleria');
}

public function tg() 
{
    $this->load->view('tgaleria');
}
}

?>

Views:

<!DOCTYPE html PUBLIC>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Galería de imágenes</title>

<style type="text/css">
</style>

<script src="<?php echo base_url(); ?>javascript/funciones.js"  
    language="javascript" input="type/text">
</script>
</head>
<body>

<div id="imgs">
<img src="imagenes/imagen1.jpg" id="eimg">
</div>

<input type="button" id="bant" onclick="imgav('atras')" value="Anterior"></button>
<input type="button" id="bsig" onclick="imgav('adelante')" value="Siguiente"></button>

</body>
</html>

View tgaleria.php:

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Galería de imágenes</title>

<style type="text/css">
</style>

<script src="<?php echo base_url();?>javascript/funciones.js"  
    language="javascript" input="type/text">

</script>
</head>
<body>

<div id="imgs">
<img src="imagenes/imagen1.jpg" id="eimg">
</div>

<input type="button" id="bant" onclick="imginter('arrancar')" value="Arrancar">   
</button>
<input type="button" id="bsig" onclick="imgparar()" value="Parar"></button>

The default controller is galeria.php.

$route['default_controller'] = "galeria";

When I type http://example.com/codeigniter I have everything ok.

But when I type http://example.com/codeigniter/tg.php I obtain the error 404, url not found.

How can I fix it?

Thanks.

1
Did you try just http://example.com/codeigniter/tg without the extension? Frameworks usually do some mod_rewrite magic for pretty URL's. - Jeremy Harris
Yes, I tried it, but it doesn't work. - axmug
Also there is a spell error in url.. its codeigniter not codeingniter :) - Jigar Jain
Have you used .htaccess to remove the index.php? if not then you must append it like http://example.com/codeigniter/index.php/galeria/tg else http://example.com/codeigniter/galeria/tg - Nil'z
Yeah. Error of tipying. But this is not the problem. If I typed it correctly the error is not fixed. - axmug

1 Answers

2
votes

Have you used .htaccess to remove the index.php? if not then you must append it like:

http://example.com/codeigniter/index.php/galeria/tg 

else

http://example.com/codeigniter/galeria/tg

Here, galeria being your Controller and the first segment and tg your function and the second segment of the URI.