I'm following this tutorial on CodeIgniter:
http://ie.mirror.twsweb-int.com/codeigniter/user_guide/tutorial/index.html
4th page of tutorial:
http://ie.mirror.twsweb-int.com/codeigniter/user_guide/tutorial/create_news_items.html
In the 4th page of the tutorial, he mentions that you should create your own successful entry page.
I want to create a link on the success.php that links back to the index page (calls news_index). IE in terms of URLs, I want a link that goes from
http://example.com/codeigniter/index.php/news/create
to
http://example.com/codeigniter/index.php/news/
How are dynamic URLs like that made on CodeIgniter?
First load the URL helper in your controller or Autoload file.
Then use the site_url()
function and just pass news.
<?php echo site_url('news');?>
If you take a look at this page - http://ie.mirror.twsweb-int.com/codeigniter/user_guide/helpers/url_helper.html you can see how the site_url()
function works.
You just echo site_url('controller/method/segment1/segment2/etc'); so if you wanted to link to the http://example.com/codeigniter/index.php/news/
page you can do
<?php echo site_url('news'); ?>
and if you wanted to link to the http://example.com/codeigniter/index.php/news/create
you can do
<?php echo site_url('news/create'); ?>
您可以在config.php
设置site_url/base_url
并在autoload.php
文件中autoload.php
URL helper。
您可以在 codeigniter 文件的 routes.php 上配置它们。
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.