CodeIgniter Forums

Full Version: URL Helper not loading?
You're currently viewing a stripped down version of our content. View the full version with proper formatting.

El Forum

[eluser]WoolyG[/eluser]
Hi all,

I'm new around here, and this is the first of many frivolous questions, I'm sure. I've been knocking my head off this for hours, to no avail, so hopefully someone can shed some light.

My URL Helper seems not to be loading, for a simple setup.

Controller Code:
Code:
class Validator extends Controller{

    function Validator(){
        // Load Parent
        parent::Controller();
        // Load URL Helper
        $this->load->helper('url');
        // Load Form Helper
        $this->load->helper('form');
        //Load Validation Class
        $this->load->library('validation');
    }
    
    function index(){
        
        // Set Validation rules
        $rules['user_firstname'] = "required";
        $rules['user_lastname'] = "required";
        $rules['user_email'] = "required";
        $this->validation->set_rules($rules);
        
        // Check if form has been submitted properly
        if($this->validation->run() == FALSE){
        //Redisplay form
        $this->load->view('form_view');
        } else {
        $this->load->view('success_view');
        }        
    }

}


Success View:
Code:
class Validator extends Controller{

    function Validator(){
        // Load Parent
        parent::Controller();
        // Load URL Helper
        $this->load->helper('url');
        // Load Form Helper
        $this->load->helper('form');
        //Load Validation Class
        $this->load->library('validation');
    }
    
    function index(){
        
        // Set Validation rules
        $rules['user_firstname'] = "required";
        $rules['user_lastname'] = "required";
        $rules['user_email'] = "required";
        $this->validation->set_rules($rules);
        
        // Check if form has been submitted properly
        if($this->validation->run() == FALSE){
        //Redisplay form
        $this->load->view('form_view');
        } else {
        $this->load->view('success_view');
        }        
    }

}

When I come to the view success_view, I get the following:

Fatal error: Call to undefined function anchor() in C:\Program Files\xampp\htdocs\application\controllers\success_view.php on line 12

All input appreciated!
WoolyG

El Forum

[eluser]gyo[/eluser]
I'm afraid you'll have to knock your head a bit more. Smile
There's certainly a mistake somewhere.

El Forum

[eluser]WoolyG[/eluser]
Am I to read that & assume that it's in my code, above? Smile

El Forum

[eluser]Clooner[/eluser]
It seems you didn't post your success_view. Do you post the form to the same controller? A view shouldn't be in the controller directory!

El Forum

[eluser]gyo[/eluser]
Yep, this is a very basic functionality that works perfectly out of the box.
If it doesn't work, there must be an error in your code, one of those 'sorry I forgot to...' mistakes. Smile

Apart from this, the 'view' code is not the proper one (it's just the controller again), and you should try doing a basic test with a new controller/view, only loading the URL helper and trying the anchor().

El Forum

[eluser]WoolyG[/eluser]
Ahh. I see what I've done. Thanks for your input everyone.


For any beginners like me reading this thread for the first time, my mistake was placing the success_view.php view file into the /controllers/ directory. Once I had moved it to the views directory, my page displayed correctly, and the anchor() function worked.


I'm sure I'll have another set of silly questions soon enough!

WoolyG

El Forum

[eluser]WoolyG[/eluser]
..wow. I also posted the Validator code twice. Sorry about that, it was late here in NZ at the time, my head wasn't in the game!

El Forum

[eluser]gyo[/eluser]
Before you post anything else, just make sure you go through the guide and search the forum... Wink