how to link to other website with codeigniter - codeigniter

I'm new to codeIgniter. Can you tell me, how to link to other website url in codeIgniter?
I tired to do like this:
google
But instead it gives me this
google
It always refers to the base url, even though I don't echo base_url(); on the href.
Thanks

When creating links to external pages, you must prefix the URL with either http:// or https:// , like this:
google
Technically this has little to do with CodeIgniter, but a difference between relative and absolute URLs.
If you did want to use CodeIgniter to generate the link, do this:
$this->load->helper('url');
echo anchor('http://www.google.com', 'Google');

Related

Encrypt URL with PHP Codeigniter

I have developed a website with PHP Codeigniter. It consists of many controllers and views. I want to encrypt the URL of the site to hide the controller and function name. Currently, the URL looks like this :
www.sitename.com/controller_name/function_name
I don't want the users to see the controller and function names. Is it possible to do this now because the site is almost complete. Is there any shortcut of doing this? Please Help
You can use codeigniter URI Routing to remove your controller name from URL.
$route['url_name'] = 'controller_name/function_name';
This `www.sitename.com/url_name` will look go to `www.sitename.com/controller_name/function_name`
$route['url_name/(:any)'] = 'controller_name/$1';
This will only change your controller name.. `controller_name` to `url_name`

Redirect to web site with codeigniter

I use CodeIgniter, how to redirect user to gmail.com after hitting on a link ? I'm really stuck to do that because the link is out of my site.
Something like:
<?php echo $billet->Courriel;?>
simple use like below
Gmail
add http:// before URL

When do we need to use base_url() function in codeIgniter?

I am working on a small project and all of my urls are written without base_url() function. So I was thinking what does those base_url() functions help with my urls. I know it will prefix the url based on configs file preferences. But simply I wanna ask
What is the advantage of using them ? and whats the disadvantage of not using them ?
The main advantage is that; when you want to migrate your project to online or in a different server; you won't need to edit your hard-coded links. The base_url() will make your inside links to get their base url dynamically.
echo base_url("blog/post/123");
will return
http://example.com/blog/post/123
in example.com and will return
http://jms.com/blog/post/123
in jms.com
base_url is needed when you create login/signup with email verification or forgot password functionality (Verifying by clicking the links like this http://yourdomain.com/auth/userid/code).
This is only one example, may have lot of uses.
the difference of base_url() and site_url() is that
both returns the url of your site but site_url() returns your site url, with attached index.php or on what you have configured $config['index_page'] = ''
in application/config/config.php
example www.yoursite.com/chicken/turkey
when using base_url(): Returns your site base URL, as specified in your config file.
you will get wwww.yoursite.com
when using site_url():
you will get www.yoursite.com/index.php
site_url() is usefull if you haven't change your .htaccess and you still access your controllers with index.php
base_url() is usefull when linking your css,js,or media stuffs. Granting that you still use index.php when accessing your controller/method
Its needed every-where, or at least we should use everywhere. Do you know, absolute url is far better then relative url? So, when you are using an absolute urls for all links on your site, instead of hard coded root domain name, you can use the "base_url()" function. Moreover, CI reactor is smart enough to detect the original base url, so you even don't need to enter it in config file.
I usually using the base_url() for the correct paths to the static files (css, js, img) files and the site_url() for the links to pages. site_url() will return with url_suffix witch could be set in application/config/config.php file
Advantage:-if you not use base_url() and you want to switch directory/server of your site , you should change the path all over the project.
if you use base_url(), just change it at onece in config.php ,effect on all site.

Codeigniter anchor can't find link

I am using CodeIgniter to design a website, and I am having trouble getting anchor to work correctly.
Here is how I am using it. It is used in a file in views folder of application in codeigniter.
<?php echo anchor('/profile', 'PROFILE'); ?>
My intention is to have anchor load the profile controller, which is in the controllers of application in codeigniter. However, when I clink on the link, it says that the the file is not found.
I autoload the url helper functions alreader, and other functions from that file are working, like site_url() .
I don't know what I could have missed? Do you ave any suggestions? This is my second project with codeigniter, so I am still learning.
EDIT: Yes, I am following the naming convention in codeigniter, and the file has an index function. I tried without the forward slash and it still gives the same result.
The HTML link that this produces is localhost/profile. This is what I Should get right? Since for codeigniter, it's url/controller/function. I did a mod rewrite to remove index.php from the url, but that shouldn't be a problem, should it? I'll try and check the base url again.
Are you sure you need the leading forward slash?
Have you tried:
<?php echo anchor('profile', 'PROFILE'); ?>
You would only be using the slash if you are trying to get into the "profile" sub folder inside your controllers folder.
What helps me when urls get confusing is to type into the browser the full url to the path I want to get to (to make sure I'm not getting a 404, etc). From there you can start from the end and go back to see what you are missing.
But you generally want to start with a controller name and add the function you are calling like:
anchor(controllerName/functionName)
See CodeIgniter URL Helper for examples.
EDIT: also - you may need to check what your config base_url is set to. if there's fancy .htaccess stuff happening, your base_url needs to be set properly.
There is a very simple solution go to config/constants and define SITE_URL there and set its value to
http://localhost/myprojectname/index.php.
Then use it here like this.
<?php echo anchor(SITE_URL.'/profile', 'PROFILE'); ?>

Joomla pagination not working with alias url

I am working on joomla application. I am using SEO url for accessing application page, but some of page use alias. When I use pagination on alias pages it will give page not found error, but with SEO url it's working fine. Anybody have any suggestion for use pagination on joomla alias page.
SEO url: http://example.com/community/inbox
Alias url: http://example.com/inbox.html
Thanks
You should always use the non-url-safe notation in your code and add JRoute to it. This might look like this:
$link = JRoute::_(JURI::base()."index.php?option=com_yourcomponent&view=yourcomponent&Itemid=1&limitstart=20");
Above is a link to the second page in a component view, when displaying 20 items a page. Hope it helps.

Resources