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');
Related
Here is my pages.php:
<?php
defined('BASEPATH') OR exit('No direct script access allowed');
class Pages extends CI_Controller {
public function index()
{
$this->load->view('home');
}
public function event()
{
$this->load->view('event');
}
public function envi()
{
$this->load->view('envi');
}
public function tour()
{
$this->load->view('tour');
}
Can you guys help me out when click on button localhost/social/pages/envi this is opens.. but i need that file should be access and url should localhost/envi how to do that can u guys help me
There are number of ways for doing this
Like you can set apache rule in .htaccess file OR
Define your routing in this file
application/config/routes.php
Put this line of code in routes.php
$route ['envi'] = "social/pages";
URL will go like this
http://localhost/envi
Hi ShanmukSrinivas Gandepalli,
There a file routes.php in the config folder, open it add define your action here
Like below, here home is controller name and aboutus is method name. Now you can call this by aboutus no need to add contoller in the url.
$route['aboutus'] = 'page/aboutus';
Hope this will help you!
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...)
I am new to coding and have fallen in love with codeigniter and recently moved from a wamp server to a LAMP server. I've extracted codeigniter into /var/www/ and set the root directory of the host in apache. I can see the codeigniter welcome page, however if I change the default controller in config.php to my controller and load this controller:
class Site extends CI_Controller {
public function index() {
$this->load->view('home_view');
}
}
I get this text in my browser:
$this -> load -> view ('home_view'); }}
The only line of my index function as well as a codeigniter generated 404 error below it.
base_url() and default controller are set, codeigniter welcome page works fine, but my page does not.
Does anyone have an idea as to why? Your help is very much appreciated.
Make sure your controller is inside application/controllers and the name is site.php
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Site extends CI_Controller {
public function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('home_view');
}
}
I have set up a folder with a controller in it: controllers/admin/home.php, but I get a 404 from the browser when I try to access it.
This is my routes file:
$route['employers'] = "employers/home";
//$route['employers/dash'] = "employers/dash";
$route['default_controller'] = "home";
$route['404_override'] = '';
This is the controller file:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class home extends CI_Controller {
function __construct(){
parent::__construct();
/*
enable profiler
*/
//$this->output->enable_profiler(TRUE);
$this->load->helper('url');
$this->load->library('ion_auth');
$this->load->library('session');
$this->load->library('form_validation');
$this->load->helper('layout');
}
}
.htaccess seems fine standard. Any ideas on what i'm doing wrong?
Note some things:
1) Routes are executed in the order they're written, and your custom routes MUST follow the default ones. So, it should be:
$route['default_controller'] = "home";
$route['404_override'] = '';
$route['employers'] = "employers/home";
This if your controller "home" is inside the folder "employers".
2) Controllers don't need all that stuff you wrote, indeed you don't even need to call the parent constructor unless you're planning to load libraries and resource for the whole controller's methods (which can be achieve also by autoloading them in the autoload.php file), so it could simply be:
file: application/controllers/employers/home.php
class Home extends CI_Controller {
function index()
{
// this is the method you're calling with your URL!
}
}
3) As per above, and as already pointed out by #Wesley, with your url you're trying to access the INDEX method of your controller HOME in your subfolder EMPLOYERS. But you didn't defined an index() method (which is the one called by default if no other is supplied).
It seems, instead, that CI is trying to look for an employers controller and a home method; if it doesnt find it, but you have a employers folder, it tries to access the index method in the home controller in the employers folder. And, since it didn't find it either, you're getting the 404 page.
Hope I'm clear, otherwise just ask.
You failed to say how you were trying to access it via url. It should be:
{YOUR_BASE_URL}admin/home
... followed by optional URL segments (/method/param1/param2/etc).
Without the additional segments, this would by default load the index method. However, since you don't have any methods defined, there's nothing to load.
If this still fails after you define a method, move the controller file out of the sub-directory for starters, and make sure it works.
I am trying to use a template library with my current codeigniter project. However I am getting the following error message,
Unable to load the requested file: main.php
My file system looks like this,
/application
/themes
/views
/layouts
admin.php
In MY_Controller.php I have the following,
<?php
class Dashboard extends MY_Controller {
public function __construct()
{
parent::__construct();
}
}
?>
In my controller I have the following
<?php
class Dashboard extends MY_Controller {
public function __construct()
{
parent::__construct();
//$this->template->set_layout('admin');
}
public function index()
{
$this->template
->set_layout('admin') // application/views/layouts/two_col.php
->build('welcome_message'); // views/welcome_message
}
}
It depends what template system your using, from the sounds of it you're using Phil Sturgeon's template library.
If so open up config/template.php
and find this line:
$config['layout'] = 'main';
And edit it as applicable.
Which template system are you using? I guess it needs a file named main.php which will load the view. Or the file does not exist and you will have to add it or the path to the file is not correct