ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Problem autoloading helpers..

November 15, 2009 1:59pm

Subscribe [2]
  • #1 / Nov 15, 2009 1:59pm

    teamcoder

    2 posts

    Hello everyone,

    I am a newbie to PHP,well to coding in general but am picking it up pretty well, and thanks to some great informative sites out on the net things are going great, I have just one issue I cannot seem to resolve.

    I am using XAMMP and everything is working as planned and am able to code everything and it is all working well except I cannot seem to get the helpers to help, i am getting

    “Fatal error: Call to undefined function form_open() in C:\xampp\htdocs\codeigniter\system\application\views\newsletter.php on line 21”

    I have set up the autoloader to load the form_helper and the url_helper but it does not seem to be loading it, I have even tried loading it the control file as such

    This is my view file

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  
    
    <html>  
      <head>  
        <title>News Letter</title>  
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">  
      </head>  
        
      <body>  
     
            
        <div id = "newsletter_form">
            
            <?php echo form_open('email/send');?>
            
            <?php
            
            $name_data = array(
                'name' => 'name',
                'id' => 'name',
                'value' => set_value('name')
            );
            
            ?>
            
            <label for="name">Name: </label><?php echo form_input($name_data); ?>
            
            
                <label for='name'>Email Address:</label>
                <input type='text' name='email' id-'email' value='<?php echo set_value('email');?>'>
            
            
            <?php echo form_submit('submit',"Submit");?>
            <?php echo form_close(); ?>
            
        </div>
     
      </body>  
    </html>

    And here is my controller file

    <?php
    
    Class Email extends Controller
    {
        function __construct()
        {
            parent::Controller();
        }
        
        function form()
        {
            $this->load->helper('form');
        }
        
        function index() 
        {
            $this->load->view('newsletter');
        }
        
        function send()
        {
            
            $this->load->library('email');
            $this->email->set_newline("\r\n");
            
            $this->email->from('*********.com', '*****');
            $this->email->to('**********.com');
            $this->email->subject('This is an email test');
            $this->email->message('Its working yippie');
            
            $path= $this->config->item('server_root');
            $file = $path . '/codeigniter/attachment/yourinfo.txt';
            
            $this->email->attach($file);
            
            if($this->email->send()){
                echo 'Your email was sent';
            }
            else{
                show_error('$this->email->print_debugger()');
            }
        }
    }
    ?>


    If anyone has any thoughts as to how I can set it up to work, I am running it on WindowsXP, codeigniter is setup in my htdocs folder and as I said other apps that I have written have all worked out great but everytime I try to use the form_helper I have the same issues.

    PLEASE HELP ME!!!! :ahhh:

  • #2 / Nov 15, 2009 2:14pm

    jedd

    2089 posts

    Hi teamcoder and welcome to the CI forums.

    Try moving your form loader into the autoload.php (application/config/) file, or at the very least load it in the same method of your controller that then calls the view.

    That is, move this line:

    $this->load->helper('form');

    - from out of your form() method and into your index() method.

    I’d suggest that your code will probably morph a fair bit, so for the moment stick it in autoload.  You can selectively load things like this if / when performance becomes relevant.

  • #3 / Nov 15, 2009 3:20pm

    teamcoder

    2 posts

    Thanks for the fast respond and the welcome,

    Well everything you had mentioned I had done or is already done, here is my autoloader file.

    <?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
    /*
    | -------------------------------------------------------------------
    | AUTO-LOADER
    | -------------------------------------------------------------------
    | This file specifies which systems should be loaded by default.
    |
    | In order to keep the framework as light-weight as possible only the
    | absolute minimal resources are loaded by default. For example,
    | the database is not connected to automatically since no assumption
    | is made regarding whether you intend to use it.  This file lets
    | you globally define which systems you would like loaded with every
    | request.
    |
    | -------------------------------------------------------------------
    | Instructions
    | -------------------------------------------------------------------
    |
    | These are the things you can load automatically:
    |
    | 1. Libraries
    | 2. Helper files
    | 3. Plugins
    | 4. Custom config files
    | 5. Language files
    | 6. Models
    |
    */
    
    /*
    | -------------------------------------------------------------------
    |  Auto-load Libraries
    | -------------------------------------------------------------------
    | These are the classes located in the system/libraries folder
    | or in your system/application/libraries folder.
    |
    | Prototype:
    |
    |    $autoload['libraries'] = array('database', 'session', 'xmlrpc');
    */
    
    $autoload['libraries'] = array('database');
    
    
    /*
    | -------------------------------------------------------------------
    |  Auto-load Helper Files
    | -------------------------------------------------------------------
    | Prototype:
    |
    |    $autoload['helper'] = array('url', 'file');
    */
    
    $autoload['helpers'] = array('url', 'form');
    
    
    /*
    | -------------------------------------------------------------------
    |  Auto-load Plugins
    | -------------------------------------------------------------------
    | Prototype:
    |
    |    $autoload['plugin'] = array('captcha', 'js_calendar');
    */
    
    $autoload['plugin'] = array();
    
    
    /*
    | -------------------------------------------------------------------
    |  Auto-load Config files
    | -------------------------------------------------------------------
    | Prototype:
    |
    |    $autoload['config'] = array('config1', 'config2');
    |
    | NOTE: This item is intended for use ONLY if you have created custom
    | config files.  Otherwise, leave it blank.
    |
    */
    
    $autoload['config'] = array();
    
    
    /*
    | -------------------------------------------------------------------
    |  Auto-load Language files
    | -------------------------------------------------------------------
    | Prototype:
    |
    |    $autoload['language'] = array('lang1', 'lang2');
    |
    | NOTE: Do not include the "_lang" part of your file.  For example 
    | "codeigniter_lang.php" would be referenced as array('codeigniter');
    |
    */
    
    $autoload['language'] = array();
    
    
    /*
    | -------------------------------------------------------------------
    |  Auto-load Models
    | -------------------------------------------------------------------
    | Prototype:
    |
    |    $autoload['model'] = array('model1', 'model2');
    |
    */
    
    $autoload['model'] = array();
    
    
    
    /* End of file autoload.php */
    /* Location: ./system/application/config/autoload.php */

    If any other possibilities please let me know, again thanks for the help.

  • #4 / Nov 15, 2009 7:10pm

    jedd

    2089 posts

    Have you changed your controller / view code too?  If you have the form helper being autoloaded, you don’t need to load it in your controller.


    When posting a lump of code with an error like ‘at line xyz, this error happens’ - it’s polite to identify the line number in your code.  Line 21, by my count, for example, is not an error-producing line.

  • #5 / Nov 15, 2009 8:31pm

    wiredesignz

    2882 posts

    Do you notice the problem you have if you compare your autoload script to this copy of the original.

    $autoload['helper'] = ...
  • #6 / Nov 15, 2009 9:25pm

    teamcoder

    2 posts

    I’m sorry lab,

    I did post the error and the line in my first post, sorry I didn’t repeat myself,but I have taken it out of the controller file and let it run from the autoloader, no luck then I tried it vice versa, still no luck, it just won’t build the form and spit’s out that error.

    Fatal error: Call to undefined function form_open() in C:\xampp\htdocs\codeigniter\system\application\views\newsletter.php on line 21

    SoI don’t know where to go from here, I have my codeigniter folder in my htdocs folder where it should be, it sends emails like it should, but it won’t build the form, and I had the same problem in another app I tried to put together.

    I’m stumped,anyone else have any ideas?

  • #7 / Nov 16, 2009 12:23am

    Aken

    2430 posts

    Did you change your autoload key to ‘helper’ as wiredesignz suggested?

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases