Welcome Guest, Not a member yet? Register   Sign In
Problem autoloading helpers..
#1

[eluser]teamcoder[/eluser]
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
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">  

&lt;html&gt;  
  &lt;head&gt;  
    &lt;title&gt;News Letter&lt;/title&gt;  
    &lt;meta http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;  
  &lt;/head&gt;  
    
  &lt;body&gt;  

        
    <div id = "newsletter_form">
        
        &lt;?php echo form_open('email/send');?&gt;
        
        &lt;?php
        
        $name_data = array(
            'name' => 'name',
            'id' => 'name',
            'value' => set_value('name')
        );
        
        ?&gt;
        
        <p><label for="name">Name: </label>&lt;?php echo form_input($name_data); ?&gt;</p>
        
        <p>
            <label for='name'>Email Address:</label>
            &lt;input type='text' name='email' id-'email' value='&lt;?php echo set_value('email');?&gt;'&gt;
        </p>
        
        <p>&lt;?php echo form_submit('submit',"Submit");?&gt;</p>
        &lt;?php echo form_close(); ?&gt;
        
    </div>

  &lt;/body&gt;  
&lt;/html&gt;

And here is my controller file
Code:
&lt;?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()');
        }
    }
}
?&gt;


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

[eluser]jedd[/eluser]
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:
Code:
$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

[eluser]teamcoder[/eluser]
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.
Code:
&lt;?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

[eluser]jedd[/eluser]
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

[eluser]wiredesignz[/eluser]
Do you notice the problem you have if you compare your autoload script to this copy of the original.
Code:
$autoload['helper'] = ...
#6

[eluser]teamcoder[/eluser]
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

[eluser]Aken[/eluser]
Did you change your autoload key to 'helper' as wiredesignz suggested?




Theme © iAndrew 2016 - Forum software by © MyBB