Reputation: 1724
I am confused why this link is not clickable or nothing happens in chrome, and in mozilla returns error something like 'address wasn't understood'...
HTML markup exactly is this
<li><a href="<?php echo site_url('makers/create_makers')?>">Add new Makers</a></li>
which in turn, produce something like
<li><a href="localhost:8089/makers/create_makers">Add new Makers</a></li>
The weird part is adding 'index'
<li><a href="localhost:8089/makers/create_makers/index">Add new Makers</a></li>//works
Which means I have to add 'index' in every link created in order to work
Controller
public function create_makers()
{
$this->load->helper('form');
$this->load->helper('url');
$this->load->library('form_validation');
$data['title'] = 'Add New Car Maker';
$data['content'] = 'makers/create_makers';
$data2['content']='makers/success';
$this->form_validation->set_rules('name','name','required');
$this->form_validation->set_rules('description','description','required');
$this->form_validation->set_rules('nation_id','nation_id','required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('templates/layout', $data);
}
else
{
$this->makers_model->new_makers();
$this->load->view('templates/layout',$data2');
}
}
Inside config/config.php
$config['base_url'] = 'localhost:8089';
$config['index_page'] = 'index.php';//remove or not remove same still not working
routes
$route['makers/create_makers'] = 'makers/create_makers';
$route['default_controller'] = 'services/index';
.htaccess is put inside root folder(outside application folder)
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule .* index.php/$0 [PT,L]
I also tried to remove htaccess and put inside application folder but nothings happen when clicking the link
However if I manually add a trailing 'index', this will work.
localhost:8089/makers/create_makers//doesn't work
localhost:8089/makers/create_makers/index //works!
I am confuse about this in Codeigniter
Inside apache
<VirtualHost *:80>
#ServerAdmin webmaster@localhost
DocumentRoot /var/www/CodeIgniter-3.0.3/
#AcceptPathInfo On
<Directory /var/www/CodeIgniter-3.0.3/>
Options FollowSymLinks Indexes
AllowOverride All
Require all granted
</Directory>
# Available loglevels: trace8, ..., trace1, debug, info, notice, warn,
# error, crit, alert, emerg.
# It is also possible to configure the loglevel for particular
# modules, e.g.
#LogLevel info ssl:warn
#ErrorLog ${APACHE_LOG_DIR}/error.log
#ErrorLog ${APACHE_LOG_DIR}/error.log
#CustomLog ${APACHE_LOG_DIR}/access.log combined
ErrorLog /var/www/CodeIgniter-3.0.3/application/logs/error.log
CustomLog /var/www/CodeIgniter-3.0.3/application/logs/access.log combined
mod_rewrite is enabled
Any help is appreciated
Upvotes: 0
Views: 134
Reputation:
Lets tweak your .htaccess and see if it works
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
<Files "index.php">
AcceptPathInfo On
</Files>
And remove index.php in your config file
$config['index_php']='';
And according to the codigniter docs
A URL containing the word “journals” in the first segment will be remapped to the “blogs” class.
$route['journals'] = 'blogs';
so lets apply this in your route file
$route['makers/new_makers'] = 'makers/create_makers';
Now your link will work without appending 'index' ..Something like
<li><a href="<?php echo site_url('makers/new_makers')?>">Add new Makers</a></li>
Remember, url inside $route[''] should mapped to a class and its method.In this case the url
<?php echo site_url('makers/new_makers') ?>
Will look to the controller Makers and its method
create_makers()
which then render the view that contains create_makers.php inside the makers folder in your view folder.
Upvotes: 2
Reputation: 490
You either have to load the url helper in the autoload file or in the construct of the controller.
Your url should look like this:
<li><a href="http://localhost:8089/makers/create_makers">Add new Makers</a></li>
If you don't have the http:// it won't work.
In addtion, you have to leave the $config['base_url']
blank and $config['index_page']
.
Upvotes: 0