سؤال

I'm building a site and would like to create a list of reserved usernames to keep people from creating usernames like account, index, profile and others. I already have my list, I'm just not sure where in Codeigniter to store this data/array.

I'm pretty familiar with Codeingiter and I like to keep things where they are suppose to be. Helpers, libraries and configs just don't seem like places to store an array of reserved variables... but maybe i'm wrong.

I would appreciate suggestions! Thanks in advance.

هل كانت مفيدة؟

المحلول

It depends on your need and preference, config is right but helper is also right because if you keep it in helper file then you may also create a helper function right there, for example

function is_reserved_username($username)
{
    $reserved_words = array('account', 'index');
    return in_array($username, $reserved_words);
}

So, from anywhere, you can use

if(is_reserved_username($this->input->post('username'))) {
    // it's a reserved word
}

Also, if you are using your own base controller (MY_Controller) then you may keep it in that base controller, so it'll be available in every classes and you can access it using something like

In MY_Controller if it's available as

$reserved_words = array('account', 'index');

Use it from a controller/model

if(in_array($username, $this->reserved_words)) {
    // it's a reserved word
}

نصائح أخرى

I don't think there is any "right" way to do this. Personally I would just create a table in my database. I'd then create a function that would check this table for reserved names when a new user is registering and return TRUE if the username isn't reserved and FALSE if it is reserved

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top