Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
PSR-0 Example Issue
<?php
use SomeGuys/Email;
namespace App/Controller;
class Contact extends /App/Controller {
public function action_index() {
// On submist
if($this->input->post('submit')) {
// Validation rules
$validation = Validation::factory($this->input->post())
->rule('name', 'not_empty')
->rule('name', 'max_length', 50)
->rule('email', 'email::valid')
->rule('message', 'not_empty');
// If valid, send email
if($validation->valid()) {
$email = Email::compose()
->to('owner@domain.com')
->subject("From {$validation->name}")
->message($validation->message)
->send();
}
}
// Show contact form
$view = View::factory('contact-form');
$this->response->body($view);
}
}
@Dachande663

This comment has been minimized.

Copy link
Owner Author

commented Sep 20, 2012

This is a simple example of where PSR-0 can cause issues. This (pseudo-)code would work correctly on a development Mac, but fails when deployed to a Linux staging environment. PHP compiler would issue an error for line 21, class 'email' not defined. Guess why?

@Dachande663

This comment has been minimized.

Copy link
Owner Author

commented Nov 7, 2012

Forgot to add, when removing the validation rule the email sends correctly, using the same class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.