base_url() not getting translated
I have inherited an app that was built with Code Igniter. I've set up the environment and loaded the app on a new machine and I'm having an issue with the call to base_url() not working.
Here is the code as it is in the view:
<a href="<?= base_url();?>index.php/study/start">Start Study Analysis »开发者_JAVA技巧 </a>
When the page is rendered, this is the URL that is created:
<a href="<?= base_url();?>index.php/study/start">Start Study Analysis »</a>
It appears that the function call is not taking place and the code is being inserted as plain text. I've looked at the config.php file and the base_url is set in there. The helper is being loaded in the autoload.php file and I've even tried to load the helper in the view.
Does anyone have any idea as to why this is happening?
Here is the code as it is in the view:
a href="< ?= base_url();?>index.php/study/start">Start Study Analysis » /a>
Either this is a formatting mistake in your post, or you just have a really mangled link there.
I'm going to take a guess that you do have a space between your <
and ?=
, which would indeed cause the code not to be parsed as php, but instead as broken text/html.
%20
is a url encoded space character, so it makes sense that this is what you'd see in your url.
Make sure there are no spaces in your PHP opening tag:
<?php echo base_url(); ?>
and not< ?php echo base_url(); ?>
<?= base_url(); ?>
and not< ?= base_url(); ?>
There isn't a space there. I needed to add it [for formatting the post]
The only other thing I can think of is that short tags are not enabled, but I admit that I do not know if this would be your result if that was the case. Try using <?php echo
instead of <?=
, or enabling the rewrite_short_tags
option in your config.php
. This certainly is not an issue specific to base_url()
or anything similar, your php tags are getting parsed as plain text so what's inside them does not matter at all.
精彩评论