Solved thread

This post is marked as solved. If you think the information contained on this thread must be part of the official documentation, please contribute submitting a pull request to its repository.

Getting model property metadata

How do I determine specific metadata about a model property? For example, I want to ensure that a value I store in a propery won't exceed the length of that column as defined in the database. I realise this is something related to model metadata, but the Phalcon's "Models Metadata" documentation seems to focus on metadata caching and metadata strategies, and doesn't show any examples of how to actually get something like a column's length (as defined in the database).


Hey, hope this quick snippet helps :)

$columns = $this->db->describeColumns('halls'); // Table name
foreach ($columns as $column) {
    echo 'Name: ', $column->getName(), '<br/>';
    echo 'Type: ', $column->getType(), '<br/>'; // Column types constants
    echo 'Size: ', $column->getSize(), '<br/><hr/>';

Related links: