Hi everyone I am new to a PHP framework codeIgniter, I am going over the user guide iv ran in to a problem, I am on the part where you load helper file but for some reason my code just in not working I keep getting this error:
Fatal error: Call to undefined function anchor() in /home/fresherd/public_html/CI/system/application/views/blogview.php on line 17
now im not 100% sure that it is loading the helper file this could be causing the but I am not sure how to detect the file has been loaded
any advice will help many thanks, Alan
If you are not sure please check the autoload.php file in the config folder or in your controller put the following function:
<?php
function __construct(){
parent::__construct();
$this->load->helper('url');
}
?>
Just add url in helper inside autoload.php inside config folder.
$autoload['helper'] = array('url');
or you can add this inside your function
$this->load->helper('url');
Just load the helper in your controller or put it in the auto load array.
$this->load->helper('url');
I would also change Gerardo's code to this:
function _construct() {
parent::__construct();
}
loading the helper in the controller solved my problem,, jus try this way
<?php
function __construct(){
parent::__construct();
$this->load->helper('url');
}
?>
or try putting it in autoload array in config.php in the application/config folder., like
$this->load->helper('url');
hope it helps...
Make sure that your controlLer, has the parent statment in the construct
function __construct(){
parent:: ControlLer();
}
You can autoload your helper so you dont have to reload it on every page..
$autoload['helper'] = array('url');
or manually load it on every page..
$this->load->helper('url');
Related
I have checked all config files, made sure the helpers are in both system/helpers and application/helpers as well as one or the other. I have tried autoloading helpers, loading the helper in my controller and from the view and no matter what I get an error.
Unable to load the requested file: helpers/_helper.php
It is treating it as if I am trying to load a blank helper such as $this->load->helper(''); but I am using $this->load->helper('url');
This is my controller to load my home page
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pages extends CI_Controller {
public function __construct(){
parent::__construct();
$this->load->helper('url');
}
public function index(){
$this->load->view('templates/header');
$this->load->view('home');
$this->load->view('templates/footer');
}
}
system/helpers/url_helper.php and application/helpers/url_helper.php both currently exist and have not been edited at all.
If needed I can include my autoload.php but the helper Auto-load Helper Files is currently $autoload['helper'] = array();
If you need to over ride the url helper
rename the file
application/helpers/MY_URL_helper.php
OR
application/helpers/MY_url_helper.php
Copy the whole path inside the url, like this , (wamp)
$this->load->helper('www/projectfoldername/applications/libraries/helpers/helperfile');
I have this code file in Codeigniter, but the URL method doesn't work also try so really I don't see problem here.
<?= link_tag('asstes/css/bootstrap.min.css') ?>
load through helper $this->load->helper('html');
What am I doing wrong?
On CodeIgniter 3 versions Just check if your base_url is set because some times having that blank can cause links not to work properly.
$config['base_url'] = 'http://localhost/your-project/';
Controller example: Welcome.php
<?php
class Welcome extends CI_Controller {
public function __construct() {
parent::__construct();
$this->load->helper('html');
}
public function index() {
$this->load->view('welcome_message');
}
}
Or auto load html helper
$autoload['helper'] = array('url', 'html');
In your head tag on view link_tag guide
<html>
<head>
<?php echo link_tag('assets/css/bootstrap.css');?>
</head>
Folder Example
application
assets
system
index.php
You have an error in your string path
asstes ---> assets
I think it's better to write your own helper for add your resources (js, css...)
In the codeigniter I get this message :
Unable to load the requested file: home.php
controller :
cp/
Login
views :
cp/
home.blade.php
class Login extends BaseController {
public function __construct(){
parent::__construct();
}
function index()
{
$this->load->view('home','');
}
}
or :
class Login extends BaseController {
public function __construct(){
parent::__construct();
}
function index()
{
$this->load->view('cp/home','');
}
}
http://www.vitrinsaz1.ir/Mobile/Vitrinsaz/Pannel/cp/login
Hi when loading views remember to make sure that you name it correctly like in your instance you could do the following:
function index()
{
$this->load->view('home_blade');
}
remove the period in the name of the file and replace it with a underscore and then make sure the view file itself is named home_blade.php
Hey there I was also encountered by this error and my error was solved by rechecking the parent folder name try replacing cp.
$this->load->view('cp/home');
with this
$this->load->view('Cp/home');
I think this could be the issue..
My code was working fine on localhost but on server it wasn't loading the view. my error was solved by this.
If the code is correct and you still experiencing that error, change folder permissions :
chmod -R 777 "your folder"
I had a similar problem and that solved it.
When using Codeigniter to load the database, I am getting the following error message in a simple file where I load the database:
An Error Was Encountered
Unable to load the requested class: database
The controller for this code is called db.php, and the code for it is as follows:
<?php
class Db extends MY_Controller {
function __construct() {
parent::__construct();
$this->load->library('database');
}
public function index() {}
}
I do not have the database loaded in to autoload.php. I also know that I have the correct database information in my config.php file. My CodeIgniter application is in a subdomain if that might cause any problems.
Any ideas on what could be causing the problem? Thanks.
Use $this->load->database();
Instead of $this->load->library('database');
Currently I display images in the following way:
<img src="<?php echo base_url().USER_UPLOAD_URL.$post['userPhoto'] ?>" />
USER_UPLOAD_URL is defined inside application/config/constants.php.
define('USER_UPLOAD_URL', "uploads/user_uploads/");
Is there any way to include base_url() inside constants.php? In this way I wouldn't need to write each time base_url() inside view. Is there any alternative approach?
tnx
constants.php loading before config.php, so you can't use $config['base_url'] from constants.php.
But you can do something like that:
constants.php:
define('BASE_URL', "http://mysite.com");
define('USER_UPLOAD_URL', BASE_URL."uploads/user_uploads/");
config.php
$config['base_url'] = BASE_URL;
You can't use base_url() in the constants file because the constants file is loaded first, and the base_url() is only loaded when you either autoload the url helper, or load it per controller.
Here's a suggestion though, you could possibly define it in your controller:
public function __construct()
{
$this->load->helper('url');
define('USER_UPLOAD_URL', base_url('uploads/user_uploads/'));
}
Which would then be accessible to the view.
I'd complement the #Dale answer making use of a custom controller. At first place, create the controller at /application/core/GeneralController.php:
<?php
class GeneralController extends CI_Controller{
public function __construct()
{
parent::__construct();
$this->load->helper('url');
define('USER_UPLOAD_URL', base_url('uploads/user_uploads/'));
}
}
Now, you can extends all controllers from GeneralController instead of CI_Controller, because USER_UPLOAD_URL is now defined
It is an old question still i overcame this issue using APPPATH.
APPPATH works inside constants.php. but it returns path as var/www/html/projectfolder/application inside application folder you can store you data within a new folder or third_party folder.
In constants you can define as eg define('pace-min-js',APPPATH.'third_party/luna/vendor/pacejs/pace.min.js');