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
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 have a form like
<form action="abc/1" method="post">
</form>
I want every time this form is submitted my URL remains same like suppose my current URL was
http://localhost/abc/1 after form submit it should be again
http://localhost/abc/1
but instead this it become
http://localhost/abc/1
http://localhost/abc/abc/1
http://localhost/abc/abc/abc/1 each time I press submit button in form.
its something related to URL schemes of mvc in code-igniter
The action of your form is relative to your current position.
If you are on http://example.com/contact and your form's action is set to contact/send the form well send to http://example.com/contact/contact/send Now, this would be easy fixed by either removing the contact/ part form the action attribute or by adding a / in the beginning of your action attribute, so the path is absolute - /contact/send.
Doing this in CodeIgniter should be relatively easy, as you can use the URL Helper to point to the correct URL's in your application.
<form action="<?php echo site_url('abc/1'); ?>" method="post">
</form>
This example will always point you to the page relative to your base_url and index_page settings in application/config/config.php.
In your case, mentioned in the comments, something along with <?php echo site_url('home/authenticateUser/' . $user_id); ?> would probably be the answer.
Try like
<form action="/abc/1" method="post">
</form>
or else you better to use site_url like
<form action="<?php echo site_url('abc/1');?>" method="post">
</form>
Changing the action from "abc/1" to "/abc/1" will work, but if you are building your app in a subdirectory, as is usually the case on a localhost development environment, this will revert to your htdocs folder, as opposed to your required folder.
I would recommend one of two options:
<form action="<?php echo base_url(abc/1); ?" method="post">
<?php form_open('abc/1')' ?>
Number 2 is the better one, as it works with CodeIgniter's CSRF functionality, and adds the base_url() automatically.
Hope this helps.
I have this template view at view/include
<?php $this->load->view('include/header'); ?>
<?php $this->load->view($sidebar_column); ?>
<?php $this->load->view($result_column); ?>
<?php $this->load->view($footer_row); ?>
<?php $this->load->view('include/footer'); ?>
and i have the footer_row html at view/include
<div> this is footer row <?php echo $username ?></div>
then i call the footer_row in my controller
$data['footer_row'] = 'include/footer_row';
$this->load->view('include/template',$data);
My question, the footer_row is logged in user info and it appear in EVERY pages. With the above method I use, I have to call and retrieve the user info in every controller. How can i make it reusable so i don't need to repeat myself.
Reusability comes from making use of your constructors, and parent classes. Have a look at my previous answers:
Header and Footer in CodeIgniter
Constructor session validation for different functions
Instead of using this method why dont you use a template library which is easy to use. I would recommend Philsturgeons Template Library but there are some more you can use any that fits to your requirements.
Williams Concepts
http://williamsconcepts.com/ci/codeigniter/libraries/template/
Phil Sturgeons's
http://philsturgeon.co.uk/demos/codeigniter-template/user_guide/
Most Simple
http://maestric.com/doc/php/codeigniter_template
And Finally Binpresses's
http://www.binpress.com/app/codeigniter-template-library/223
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.
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');?>