I created a helper in CodeIgniter 3 which I called asset_helper.php
and this is the controller I use to call this helper:
<?php
class Index extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper('asset');
}
function index()
{
$this->load->view('header');
$this->load->view('nav');
$this->load->view('title');
$this->load->view('stat1');
$this->load->view('footer');
}
}
but when I access to the controller I get this message:
Unable to load the requested file: helpers/asset_helper.php
How can I solve this problem?
Load like this
$this->load->helper('asset_helper');
If you use like this $this->load->helper('asset'); it will never works.B Bcz there is no file call asset
Related
So I have followed every rule there is on CI docs page but still get error
Call to undefined method CI_Form_validation::clear_field_data()
I placed the file MY_Form_validation.php in application/core directory:
class MY_Form_validation extends CI_Form_validation {
public function __construct()
{
parent::__construct();
}
public function clear_field_data() {
$this->_field_data = array();
return $this;
}
}
and then in my controller I load class as usual:
$this->load->library('form_validation');
and use my new method:
$this->form_validation->clear_field_data();
$this->load->view('product/create', $data);
Which are the mistakes in my attempt to extend the library?
Your own libraries must be in the folder: application/libraries
$this->load->library('form_validation');
$this->form_validation->clear_field_data();
$this->load->view('product/create', $data);
You're loading the wrong library? Your lib should also go in application/libraries.
$this->load->library('MY_Form_validation');
$this->MY_Form_validation->clear_field_data();
$this->load->view('product/create', $data);
i am trying to make a core class in my codeigniter but its giving error that Unable to locate the specified class: Loader.php.
My Core class is MY_base.php and code is.
class MY_base extends CI_Controller{
public function load_header(){
$this->load->model('mod_practice');
$headData=$this->model->get_header();
$this->load->view('header',$headData);
}
}
My model Mod_practice.php code is
class Mod_practice extends CI_Model{
public function get_header(){
$query = $this->db->get('header');
$result = $query->result_array();
return $result;
}
}
My home.php ( main controller) code is
class Home extends MY_loader{
function index(){
parent::MY_base();
}
}
but when i try to run Home controller its giving me the following error
Unable to locate the specified class: Loader.php.
Where can be the error ? Thanks in advance.
You are doing something wrong. You need to construct CI_controller first.
class MY_base extends CI_Controller{
public function __construct()
{
parent::__construct();
// Your own constructor code
}
public function load_header(){
$this->load->model('mod_practice');
$headData=$this->model->get_header();
$this->load->view('header',$headData);
}
}
And now you can do this:
class Home extends MY_base{
public function __construct()
{
parent::__construct();
// Here you have access to load_header() function
}
}
Ou - and also your create MY_base and then refer to MY_loader.
may bee you can use HMVC Codeigniter https://bitbucket.org/wiredesignz/codeigniter-modular-extensions-hmvc
I want to do something like this in CodeIgniter:
Controller:
class Home extends CI_Controller {
public function index() {
$this->load->view('home');
}
public function user($user) {
return $user;
}
}
View (home):
Hi <?php echo user('User') ?> // call a controller method
How can i do this?
One way to get it is , returning it from the routes.php ,
Like $route['user'] = "home/user"; And this will execute the user method from the home controller.
Using CodeIgniter 2.0.3 on XAMPP 1.7.7 I have code where I get the error as: Unable to load the requested file: home.php
The home.php code as follows stored in ./ci2/application/controllers:
class Home extends CI_Controller {
function Home()
{
parent::__construct();
}
function index()
{
$this->load->view('home');
}
While using it just notice:
controller's name is home.php
File named home.php must be present in ci/views
Incase file extention in view folder is not php eg like its html.
then load it using : $this->load->view('home.html');
the function u need to call from outside must be public So make it:
public function index() {... }
as u are calling the constructor for the class Home. Call it like:
class Home extends CI_Controller {
function __construct()
{
parent::__construct();
}
public function index()
{
$this->load->view('home');
}
Now it will work !
Your call to $this->load->view('home'); will be looking for home.php in /ci2/application/views/. That's the file it can't find.
I'm assuming you're calling http://myapp/index.php/home/ - that means it'll automatically call the index() method.
class Home extends CI_Controller
{
function __construct()
{
parent::__construct();
}
function index()
{
$this->load->view('home');
}
}
Please check the name of the file you have created in application/views/, because otherwise the code is correct.
I'm using CodeIgniter (v1.7.2) and I've created a custom controller that incorporates authentication called MY_Controller (based on David Winter's blog post). When I load any controllers that use this base class, I get this error;
*Message: Undefined property: MY_Controller::$session*
Note that I am autoloading 'session' (and 'MY_controller' as a library) like so:
$autoload['libraries'] = array('database', 'session', 'MY_Controller');
Here is MY_Controller:
class MY_Controller extends Controller {
public function __construct() {
parent::__construct();
if (!$this->session->userdata('loggedin')) { <-- error is here
header('Location: /sessions/login');
exit();
}
}
}
Here's the controller that I'm trying to load:
class Welcome extends MY_Controller {
function __construct() {
parent::__construct();
}
function index() {
$this->load->view('header');
$this->load->view('welcome_message');
$this->load->view('footer');
}
}
When I var_dump $this->session above where the error occurs, I can see that it is NULL. Even putting $this->load->library('session'); in MY_Controller's constructor doesn't work. Why isn't it loading properly?
Thanks
Try taking MY_Controller out of the autoload.
$autoload['libraries'] = array('database', 'session');
You are extending the controller class which is automatically loaded by codeigniter as it is part of the core