Note the upgraded forum! If you are experiencing issues logging in, you may need to reset your password which should send an email. If the email doesn't arrive, be sure to check your spam folder just in case.

Creating Simple Modules, Tutorial

edited February 2011 in Modules
Hi,

I have went through the simple modules tutorial and I have found few minor typo mistakes and I have also one question regarding the required form fields.

1) Create the Articles Model
class Articles_model extends Base_module_model {}
class Articles_model extends Base_module_record {} // => Should be class Article_model

2) The Tree Method

function tree()
{ ...
$categories_to_articles = $CI->categories_to_articles_model->find_all('', 'name asc'); => I had to specify second parameter - categories.name otherwise I got ambiguity error.
...
}

3) Adding an After Save Hook

Everything works fine, when one selects a category for an article. If there is no category selected I get db error after hitting "save" button. It could be probably good to make category selection required, but I did not find an easy way how. Here comes my question - Can it be somehow done via public $required array?

Comments

  • edited 12:23PM
    Thanks for the bug report. I've updated the user guide and the repo. The category field actually isn't a field in the articles table so you may need to use a hook and get the validation object to add validation like so:
    $this->get_validation()->add_rule('categories', 'required, 'This field is required', $_POST['categories']);
Sign In or Register to comment.