Sounds like you’ll need both an extension and a module. They can both be stored in the same third_party package.
Got it. Is there an example of implementing them both in the same package anywhere?
Also, many thanks for answering all of my questions, Rob. Your help is invaluable.
It’s pretty straightforward to have them both in the same package. Let’s say your package is called “age_verifier”. So you’d have a folder called age_verifier that goes in system/expressionengine/third_party/. In there you’d just put your extension and module. So your folder contents would look something like:
ext.age_verifier.php //class Age_verifier_ext
mod.age_verifier.php //class Age_verifier
upd.age_verifier.php //class Age_verifier_upd
mcp.age_verifier.php //class Age_verifier_mcpThen, you’d just be sure to install the extension and the module under the Addons tab.
After an afternoon (and evening) of tinkering, I think I finally have a handle on the separation between extensions and modules.
Hopefully, this will be my final question.
How do I go about setting up views for my module? And how do I point the form I’ll create for users to input their age at the module action that will parse the form, and check their age? (Is there an example anywhere that I might have missed?)
I have a library that I’ve included to do the actual checking, and provide a list of countries around the world. Hopefully, using this data in my form view will be fairly straightforward.
Views are meant for the control panel only. You’d make a views folder in your third_party/your_package_name folder and add your view files there.
If you want to do stuff on the front end, the usual means is by template tags. So let’s say you had a method in your mod file called age_verification_form:
class Age_verifier {
public function age_verification_form()
{
$this->EE =& get_instance();
$this->EE->load->helper('form');
$output = $this->EE->functions->form_declaration_data(array(
'hidden_fields' => array(
'ACT' => $this->EE->functions->fetch_action_id(__CLASS__, 'age_verification_submit')
),
));
$output .= $this->EE->TMPL->tagdata;
$output .= form_close();
return $output;
}
public function age_verification_submit()
{
$this->EE->load->library('your_custom_age_verification_lib');
$this->EE->your_custom_age_verification_lib->verify($this->EE->input->post('age'));
//etc.
}
}This would correspond with the template tag:
{exp:age_verifier:age_verification_form}
<input type="text" name="age">
<input type="submit">
{/exp:age_verifier:age_verification_form}You’ll notice in the module’s form method I used the function fetch_action_id. This is how the form knows which method to trigger upon submission. It looks up the corresponding “action” in the exp_actions table. Which means, in your installation file (the upd file), you’ll have to be sure to actually install the action into the exp_actions table:
public function install()
{
$this->EE->db->insert('actions', array('class' => 'Age_verifier', 'method' => 'age_verification_submit'));
return TRUE;
}Whew.
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.