I can't figure out how to do the url links.
Basically I have my navigation bar, and I don't know which CodeIgniter URL code to use and how to implement it.
Is what I'm doing here right?:
<?php $this->load->helper('url'); ?>
<li>About Us</li>
I tried to do an anchor like this, but when I load the page it just turns up blank:
<?php echo anchor('views/about.html', 'About Us', title='About Us'); ?>
What am I doing wrong?
There are two ways to make links:
CodeIgniter helper style:
<?php echo anchor('about', 'About us', 'title="About us link"'); ?>
More common HTML with URL echo:
About us
Both will output:
About us
Though if I understand what you are trying to achieve, your mistake is elsewhere.
You don't include the views part, as your URL should point to the controller, not a view. The only case is if you have a controller named views.
CodeIgniter is set up so that it doesn't include file extensions like .html in URL's by default. It does if you've set them up in your config file in $config['url_suffix'] = '';, which is null by default.
See if you've made any of these mistakes.
That is another way on how you do the URL if you are using the URL helper in CI. You should try this, make the base_url() as the value for href. Try this,
About Us
You have to try like this
About Us
or you can give like
About Us
and in the "about" function you put
$this->load->view('about');
but i think the firstone will works for you fine.
Related
I'm trying to convert my core php project into CodeIgniter.
I have set the baseurl for the project in the config file i.e: http://localhost/myproject/
When I'm trying to set menu anchor href i need to pass controller_name/action_name
<a href='controller_name/action_name'> Tag_Name
I'm not able to set directly the action name for the same controller.
<a href='action_name'> Tag_Name
I have also loaded the URL helper in my Controller.
please make sure you have added this->load->helper('url'); in controller or you can add in config->autoload.
or
Go with
Link
or
<?php echo anchor('controller/function/uri', 'Link', 'class="link-class"') ?>
Any of the two should be ok.
Also refer to this link.
Or you could use base_url() function to get the value set in the config file for $config['base_url'].
Just use below code
Tag_name
Thanks You
I understand there are many answered questions on this particular issue but I haven't found anything specific to Magento, and I was wondering if changing the .htaccess file will have repercussions in my Magento store.
Basically I have links in my navigation that go straight to a filtered category page so they look as follows..
Example.com/hairproducts.html?manufacturer=412
However when I click these links they end up navigating to the URL with a trailing slash...
Example.com/hairproducts.html?manufacturer=412/
which then ignores the filter and takes them to the category page.
Cheers for any help.
I assume you have the urls generated in a phtml file like this:
<?php echo $this->getUrl('hairproducts.html?manufacturer=412'); ?>
or in a block/page content like this
{{store url="hairproducts.html?manufacturer=412"}}
Change them to this:
In a phtml file:
<?php echo $this->getUrl('', array('_direct'=>'hairproducts.html', '_query'=>'manufacturer=412'); ?>
or in a block/page content
{{store _direct="hairproducts.html" _query="manufacturer=412"}}
If I assumed wrong then post the way you are generating the urls.
I can not load controller with
http://localhost/index.php?controller/method
But if i does not use '?' and try to load a controller from view then duplicate URL produce.
As an example of above, if i add this link in form action in view then result url will be
http://localhost/index.php/controller/index.php/controller/method
How to solve it? I did not use htaccess file
Use the site_url() function or, as #JohnFable stated, use the form_open function.
<form method="post" action="<?= form_open('controller/method'); ?>">
or
Controller/Method
or
<?= form_open('controller/method'); ?>
This will ensure that your "base url", i.e. http://localhost is prepended correctly to the URL you want to view, i.e. http://localhost/index.php/controller/method or if you have set it up to, http://localhost/controller/method
Gavin
I would like to get a page's URL key in Magento.
For example, I have a CMS page called "What's New" with the identifier (or URL key) "whats_new". Its correct URL is therefore http://mysite.com/whats_new
Currently I use this code to echo its location:
<?php echo Mage::getBaseUrl();?>whats_new
I feel it's bad practice because its identifier (or URL key) is administrable; if its URL key or identifier changes then the link will break. What is the proper way to echo its dynamic URL key? Perhaps something similar to Wordpress's get_permalink('10')?
I think this will do what you want:
<?php echo Mage::helper('cms/page')->getPageUrl( $pageId ) ?>
Replace $pageId with the correct id for the page you are linking to and it should work.
Try this
<?php echo $this->getUrl('whats_new');?>
If you need to add url key dynamically then
<?php echo $this->getUrl($yourDynamicVariable);?>
of course you must implement the features that you need to fill the variable if url key is changed
You shoud use <?php echo Mage::getUrl('page-url.html); ?>
In CMS Page
{{store _direct="url_key"}}
If you want in .phtml file then
<?php echo Mage::helper('cms/page')->getPageUrl('url_key') ?>
Mage::getUrl(null, array('_direct' => $page->getIdentifier()));
It is also possible to retrieve the CMS page URL using the page identifier like,
<?php echo Mage::helper('cms/page')->getPageUrl('cms_page_identifier') ?>
You shoud use
{{store direct_url="whats_new/"}}
<?php echo $this->getUrl('whats_new');?>
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:
Start Study Analysis »
When the page is rendered, this is the URL that is created:
Start Study Analysis »
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.