Welcome Guest, Not a member yet? Register   Sign In
Custom helper not loading
#1

[eluser]jblack199[/eluser]
I've been fiddling with codeignigter for a while after deciding that smarty template engine is rather bloated.

I am currently working on a system and am starting with the administration panel, I am however having issues getting my custom helper to load.

file name: valid_admin_helper.php located in: application/helpers/ directory

Code:
<?php if (!defined('BASEPATH')) exit('No direct script access allowed');

/**
* Qweeri
*
* Helper object to allow the admin to check all admin specifications and if logged in.
*
* @package        My stuff
* @subpackage    is_admin
* @copyright    Copyright (c) 2011, Justin B.
* @since         Version 1.0
* @filesource
*/

/**
* valid_admin
*
* Lets you determine whether the selected user is a valid admin or not
*
*/


    function valid_admin()
    {
    }

function login_admin($params)
{
}

function logout_admin() {
}

/* End of file valid_admin (/
/* Location: ./application/helpers/valid_admin_helper.php */

Nothing too big about that -- haven't added in any of the code for the functions yet obviously. I've added this into my autoload.php like:

Code:
$autoload['helper'] = array('valid_admin', 'url');

problem is, when i visit the actual site I get:

Fatal error: Call to undefined method Welcome::valid_admin() in /home/thecodes/public_html/mystuff/application/controllers/adm/welcome.php on line 23

which here is the code for the welcome.php

Code:
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Welcome extends CI_Controller {
    
    public function index()
    {
        $in = $this->valid_admin();
        if ($in == '0' || $in == '')
        {
            redirect('adm/login/', 'refresh');
        }

    }
}

/* End of file welcome.php */
/* Location: ./application/controllers/welcome.php */

Any help figuring this out would be greatly appreciated. Thanks in advance!
#2

[eluser]idealws[/eluser]
Code:
class Welcome extends CI_Controller {
    
    public function index()
    {
        $in = valid_admin();
        if ($in == '0' || $in == '')
        {
            redirect('adm/login/', 'refresh');
        }

    }
}

Try removing the $this-> form the $this->valid_admin(). That should do the trick.
#3

[eluser]jblack199[/eluser]
Yeah i re-read the user guide on helpers and saw the correct syntax and it corrected the issue. Though I think I might be trying to go about this all wrong... I know this is an MVC but thus far all the information i'm seeing is done via VC havent seen anything from the M. Thanks for your answer on it even though I had already figured it out.

So initially to get myself started (both learning CI and learning more than the basics of jQuery) I figured I'd work on an administration panel which would include auto-redirecting to the login if you're not currently logged in or your login is expired...

So let me back this up and see if i'm doing this correctly thus far, I havent gotten very far with it as of yet...

I've got my CI installation in the root of a subdomain on one of my other domains just to try it out. I have the .htaccess set to remove the index.php from the URL and I have SEO friendly URL's in place...

in the application/controllers folder I have a subfolder named adm which makes it so i can go to http://name.domain.com/adm and have the welcome.php display. I also have the subfolder adm in the application/views folder giving me a spot to put all the 'views' of the administration panel.

So initially when you first open your browser and go to the admin panel it'll take you directly to the login page, which will also have a jquery tab element on it just in case you forgot your admin password.

Now here is some issues i could have... I plan on utilizing some of the structure that I used in smarty when I used that, and that would be having a simple constructor.php in the view which would house the header, side wrappers and the footer in the one file. then each individual page will need to be able to inject itself (using smarty it was: $smarty->assign('something', $something); ) so that it will take the place of a hidden div (if there is a better way to do it without having tons of files i'd be willing to listen to that as well)...

Then once I get the layout looking right as rain, I guess the only real portion left would be figuring out how to get the submit button to trigger jquery to either reset the password and send an email to them with the new password (for the forgotten password script) then redirect or refresh to the page stating thats the case... or check login information and either redirect back to http://name.domain.com/adm from http://name.domain.com/adm/login

The jquery ajax usage i think i could use a lot of help with in conjunction with CI as i'm used to smarty, but even with that i've only used the prototype.js and want to get away from that since jQuery looks more robust and what not...

I think there were quite a bit of questions in there -- if anyone answers them and/or includes some known working code samples (dont need it written for me, just samples of how it works and such) i appreciate it.
#4

[eluser]jblack199[/eluser]
I just spent some time watching some video tutorials on the wiki, and boy did that pretty much answer every question I had here...

I'm sure I'll have more questions as time goes on, but hopefully soon I'll be able to jump in and be able to help answer other peoples questions as well.. until that time, kudos and thanks to everyone that helps out on the forums.

- Jblack




Theme © iAndrew 2016 - Forum software by © MyBB