Verify email with codeigniter sending a codeigniter function - php

I did same as described in Verify email with codeigniter and all work seems ok from my side, but it only works when I give all the direction like: http://localhost/site_name/controller/function_name/parameter the parameter is my random code, but when I learn codeigniter it says that the links to a function we put in like this:
echo site_url('controller/function_name/parameter')
When I do this, the link doesn't work.

It looks like you need to load the url helper in your code.
Either add it system wide in the file:
application/config/autoload.php
$autoload['helper'] = array('url');
or you can define it in your controller:
$this->load->helper('url');
But just in case please ensure that you have the base_url parameter set up in your appliation/config/config.php
$config['base_url'] = 'http://localhost/site_name/';

Related

webroot entire path in Yii2

I have some trouble with an Yii2 application.
I need to put into a variabile the complete webroot path of my application, in my case www.mysite.it/language/catalogue/. When I call the function to retrieve this information, I get www.mysite.it/application/web where application/web is the root of my project.
I have tried this function:
$home = Yii::$app->request->getAbsoluteUrl();
It is any way to do what I want?
Thanks in advance.
You should use yii\helpers\Url features
http://www.yiiframework.com/doc-2.0/yii-helpers-url.html
http://www.yiiframework.com/doc-2.0/guide-helper-url.html
and eg_ for home Url::home()
$absoluteHomeUrl = Url::home(true);
or for Url:to()
$url = Url::toRoute(['language/catalogue/']);
the use of the UrlHelpers prevent your code from different url result related
to your urlManager config (with or without pretty url)

CodeIgniter baseurl not working on localhost

I am trying to use baseurl() in my application, but it's not working. I've attached two photos, and . Can anybody help me solve this?
$config['base_url'] = 'http://localhost/class-19/';
hiii...Please replace baseurl() to base_url().
In order to use base_url(), you must first have the URL Helper loaded. This can be done either in application/config/autoload.php:
$autoload['helper'] = array('url');
Or, manually:
$this->load->helper('url');
Once it's loaded, be sure to keep in mind that base_url() doesn't implicitly print or echo out anything, rather it returns the value to be printed:
echo base_url();

base_url() function won't work on error pages. Even after autoloading

I want to have nice good looking error pages. For this I need to get some CSS and JS files. But for some odd reason using base_url() does not work on the error_pages. I could of course just use href="/css/style.css" and tell it to get it from the root folder. But the website could very well be put in a different folder than the root folder. So using the / is not an option.
So my question now is why doesn't base_url() work on an error page? I have autoloaded it so shouldn't it be working?
This is what I tried when I was trying to get the base_url() from the error_404 page in the view.
In my autoload.php I have included the helper url
$autoload['helper'] = array('url', 'form');
And in my error_404 page (application/views/errors/html/error_404.php) I am echoing the base_url like so:
<?php echo base_url(); ?>
This is the error I'm getting:
An uncaught Exception was encountered
Type: Error
Message: Call to undefined function base_url()
Filename: /usr/local/www/example.com/application/views/errors/html/error_404.php
Line Number: 37
Backtrace:
File: /usr/local/www/example.com/index.php
Line: 315
Function: require_once
I'd rather not make any changes in the system folder since I don't want to redo the process every time I update Codeigniter folder.
System:
Codeigniter 3.0.6
PHP 7.0.8
Nginx 1.11.1
UPDATE:
I'd like to call base_url on every error page (db, 404, general, php, etc.).
The autoloader does not work because the autoloader loads the libraries after the error checks are finished. If there are errors like a 404 not found it will view the custom error page without loading the autoloader.
To get your base_url on a custom page you would need to add the following in your custom error page:
$base_url = load_class('Config')->config['base_url'];
Taken from:
http://forum.codeigniter.com/thread-65968-post-335822.html#pid335822
You must load the helper class to get access url functions. So, try to do first:
$this->load->helper('url');
Then you can echo it using
echo base_url();
alternatively, you can get the same result with
$this->config->config['base_url'];
In order to do this ,You must override the error pages in your routes.php file something like
$route['404_override'] = 'controller/method';
And inside method() function,You can access base_url() after loading uri helper as same as normal codeigniter controller.
$this->load->helper('uri');
echo base_url();
if we need to change the design of other php/db error pages.we can edit the following files

CodeIgniter 3 base_url function returns wrong url

I am using XAMPP, MySQL and CodeIgniter.
I already included,
$autoload['helper'] = array('url');
in autoload.php.
<?php echo base_url(); ?>
returns http://::1/mysite/ instead of http://localhost/mysite/.
Can anyone help me with this issue?
You need to make sure you have set your base_url in. Most likely because you left it blank. This is a common thing that people do not know about or forget to do.
application > config > config.php
$config['base_url'] = 'http://localhost/mysite/';
One of the issues when you try to submit form with out base url not set is will not go to correct url, when you try to submit a form so that why in codeigniter 3 all ways best to set your base_url even though not a requirement.
Also here are some htaccess for codeigniter xampp & wamp
Htaccess For Codeigniter

Codeigniter Url Problem on Server

I have some problem in codeigniter url segment problem in server..
In local server my web url is http:localhost/test/index.php/user/userGetData/3..if we want to get the 3 from url in controller function .
then we use $this->uri->?segment(3); it works.
But when uploaded on server we use url rewriting
$routes['getData'] = 'user/userGetData/$1'; and refresh the page after this change, server url look like http://www.test.com/getData/3
in controller function userGetData() $this->uri->segment(3); doesn't work.
How to fix this problem and same case in all function?
Are you sure $this->uri->?segment(3) it's work?
First, you need to change $config['base_url']
Use $this->uri->segment(2) to get data.

Categories