Welcome Guest, Not a member yet? Register   Sign In
Hiding validation callback methods
#1

[eluser]Unknown[/eluser]
Hi, this is my first post here; I'm new to CI and OOP PHP. I've been trying to pic them both up over the last few weeks and generally im starting to get it but there are some things which bug me....

I've been following the form validation documentation and I was wondering if it was possible to hide your callback methods from being accessed via the browsers address bar (as if they were standard methods) as I dont like the idea of them being viewable in the sense that someone could find them by mistake.


Thanks
#2

[eluser]jmb727[/eluser]
If your calling your methods from within the class or from inside a view file thats been loaded in the class, you can simply prefix the methods in question with 'private' or place an underscore infront of your methods name.

You could always do something like this:

Code:
class Foobar extends CI_Controller
{
    public function index() {
    
    }
    
    public function showForm() {
        if (isset($_POST['form_submit'])) {
            // post data found, call processForm method.
            $this->processForm();
        }
        else {
            // post data not found.. show form.
        }
    }
    
    private function processForm() {
        // process your form here.
    }
}

Then point your form like so:

Code:
<form method="post" action="index.php/foobar/showForm">
#3

[eluser]Johan André[/eluser]
You mean the custom validation methods, right?

Just prefix the method names with an underscore, like _check_unique() instead of check_unique().
Don't forget to add the underscore in the set_rules() too, callback__check_unique() instead of callback_checkunique().
The underscore prevents the method to be accessible from the url.
#4

[eluser]Unknown[/eluser]
[quote author="Johan André" date="1311617687"]You mean the custom validation methods, right?

Just prefix the method names with an underscore, like _check_unique() instead of check_unique().
Don't forget to add the underscore in the set_rules() too, callback__check_unique() instead of callback_checkunique().
The underscore prevents the method to be accessible from the url.[/quote]

Ah...I was adding the underscore before and it wasn't working. I know what I was doing wrong now....missing the underscore from the callback as well. Silly mistake

Thanks for you're replies Smile




Theme © iAndrew 2016 - Forum software by © MyBB