Welcome Guest, Not a member yet? Register   Sign In
URL Helper not loading?
#1

[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
#2

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

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

[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!
#5

[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().
#6

[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
#7

[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!
#8

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




Theme © iAndrew 2016 - Forum software by © MyBB