Skip to content

Instantly share code, notes, and snippets.

@devi
Created May 26, 2011 16:17
Show Gist options
  • Save devi/993453 to your computer and use it in GitHub Desktop.
Save devi/993453 to your computer and use it in GitHub Desktop.
Extend kohana sprig
<?php defined('SYSPATH') or die('No direct script access.');
abstract class Sprig extends Sprig_Core {
/**
* Returns the foreign key of the model, optionally with a table name.
*
* @param string table name, TRUE for the model table
* @return string
*/
public function fk($table = NULL)
{
$model = explode('_', $this->_model);
$model = strtolower($model[count($model) - 1]);
$key = $model.'_'.$this->_primary_key;
if ($table)
{
if ($table === TRUE)
{
$table = $this->_table;
}
return $table.'.'.$key;
}
return $key;
}
} // End Sprig
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment