I am working with codeigniter but i dont know how to put link to another page. My controller filename is aboutus.php. I gave a link like
AboutUs
My base url is
$config['base_url'] = "http://localhost/project/";
$config['index_page'] = '';
$config['uri_protocol'] = 'AUTO';
But above url not working. I write a url directly in browser and hit like
http://localhost/project/index.php/aboutus then its working fine. how to give a url? i am confused.
base_url() will echo:
http://localhost/project
where as site_url() will echo:
http://localhost/project/index.php
You want to get to http://localhost/project/index.php/aboutus but with base_url() you're only getting to http://localhost/project/aboutus which is giving you the error.
You can do two things,
this:
AboutUs
which means adding the index.php before aboutus
or this:
AboutUs
which means changing base_url() to site_url().
Make sure that you are loading the helper in the controller:
$this->load->helper(url);
Or in application/config/autoload.php go to the line which says:
$autoload['helper'] = array();
and do this:
$autoload['helper'] = array('url');
and it will be included in every controller you now have.
If you have short tags enabled you can write your a tag like this:
About Us
or if you have the url helper you can write it like this:
echo anchor('aboutus', 'About Us', 'title="About Us"');
Try site_url() instead of base_url() so index.php will not be skipped
AboutUs
https://ellislab.com/codeigniter/user-guide/helpers/url_helper.html
Also, make sure that url helper is loaded.
$this->load->helper('url'); //can also be done in config/autoload.php
Before using CI functions base_url() and site_url()
you need to load URL helper either in autoload.php or in controller itself.
If you have short tags enabled in PHP you can also write it link that:
Link Text
Use this .htaccess on your base folder
RewriteEngine on
RewriteCond $1 !^(index.php|resources|robots.txt)
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L,QSA]
If YOu still not get the result Please enable mod_rewrite in your apache server
your Project URL is look like you didn't enabled php short tags. Thats not a problem. just try this code:
About Us
Related
new at codeigniter, trying simple code to load bootstrap css files with base_url() function.tried some answers on stackoverflow,but issue not solved.
my view name is.... articles_list.php
my controller name... user.php
i edit config.php as follow 'localhost/ci';
i edit autoload.php as follow i load url helper in autoload.php
articles_list.php (loading css in view file)
<link rel="stylesheet" type="text/css" href="<?php echo base_url('assets/css/bootstrap.css') ?>" >
user.php(controller)
$this->load->helper('url');
$this->load->view('public/articles_list');
when i run my view file, css is not loading, when i check view source it should give me both stylesheet url and link address as "localhost/ci/assets/css/bootstrap.css" but when i see view source it show <link href="localhost/ci/assets/css/bootstrap.css"> and when mouse over at link it shows me localhost/ci/localhost/ci/assets/css/bootstrap.css link address. please
help me to solve this issue and help me to learn codeigniter.
Make sure you set the base_url right in application/config/config.php file:
$config['base_url'] = 'http://localhost/ci/';
And of course make sure to use the correct .htaccess:
RewriteEngine On
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
I just recently found out about url rewriting and i wanted to change my url from search.php?s=keyword&p=pagenum to search/keyword/pagenum. Therefor i created these rules in my .htaccess file:
RewriteEngine On
RewriteRule ^search/([A-Za-z0-9-]+)/?$ search.php?s=$1 [NC,L]
RewriteRule ^search/([A-Za-z0-9-]+)/([0-9]+)/?$ search.php?s=$1&p=$2 [NC,L]
The redirecting part works, i just noticed that my pictures on the search results are missing. This is my folder layout:
root/
---search.php
---images/
---{id}.jpg
in my search.php i access images like this: <img src='images/" . $id . ".jpg'>. Can anyone explain to me why this is happening and if possible how to fix it? Thanks in advance!
err, try
img src='../images/$id.jpg'>
or
img src='/images/$id.jpg'>
I am trying to open a page on clicking on a link in my codeigniter application. This is the snippet of my attempt
at the controller level this is snippet
//load return policy
function returnpolicy()
{
$this->load->view("return_policy");
}
at the view level this is the snippet
<div class="toggle">
Return Policy
</div>
on clicking on the link it does not navigate to the page. please what am I missing. am new to codeigniter
You should understand the difference between site_url and base_url first
echo base_url(); // http://example.com/website
echo site_url(); // http://example.com/website/index.php
You can rewrite it as follows :
<?php echo site_url('controller/method');?>
In HMVC
<?php echo site_url('module/controller/method');?>
So in your case
Return Policy
you can use the URL helper this way to generate an <a> tag
anchor(uri segments, text, attributes)
So... to use it...
<?php echo anchor('gotopolicy/returnpolicy', 'Return Policy', 'class="toggle-title"') ?>
Possible issue could be of htaccess,
create a file .htaccess in your root CI folder
and add below contents to it
RewriteEngine on
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule ^(.*)$ index.php/$1 [L]
Make $config['index_page'] = "";
try to remove class="toggle-title"
or try this
<div >
Return Policy
</div>
This is a link on index.php page
<?= $mbbelow['brand_name']; ?><?= $mbbelow['title']; ?>
from this link I come on page specification.php
then this url come http://www.themobilesapp.com/specification.php?url=Sony-Xperia-Z5-specifications-5246.php
in the base of url I find all data of page.
This url is not proper according to me.
Here I want to remove specification.php?url= from this above url.
Please tell me in proper and full explain way that how to remove and make new url like this
http://www.themobilesapp.com/Sony-Xperia-Z5-specifications-5246.php
I only need .htaccess or I also need to work using php code to remove this.
I will provide you all details you need here for to remove this.
Please try this in .htaccess file:
RewriteEngine On
RewriteRule ^([a-zA-Z0-9_-]+)$ specification.php?url=$1
RewriteRule ^([a-zA-Z0-9_-]+)/$ specification.php?url=$1
I have a link that looks like this
http://www.example.com/artistmusic?address=JKanyomozi
I would like to change this URL to
http://www.example.com/JKanyomozi/music
I've only been able to do this by adding music as a parameter instead of adding it to the new URL as a prefix.
In short, i've turned this URL ...
http://www.example.com/artistmusic?address=JKanyomozi&req=music
... using this rule ...
RewriteRule ^([^/]*)/([^/]*)$ /artistmusic?address=$1&req=$2 [L]
... into ...
http://www.example.com/JKanyomozi/music
But the problem with this is that for other pages like the one for the videos, this rule redirects to the same page http://www.example.com/JKanyomozi/music instead of http://www.example.com/JKanyomozi/videos
The videos page's original URL is something like this ...
http://www.example.com/artistvideos?address=JKanyomozi
Which rule can I use to change the URL above to
http://www.example.com/JKanyomozi/videos
This applies for other pages like artistevents, artistphotos and artistbiography
Thank you in advance!
Try this :
RewriteRule ^([^/]*)/([^/]*)$ /artist$2?address=$1 [L]