Created
May 26, 2011 16:17
-
-
Save devi/993453 to your computer and use it in GitHub Desktop.
Extend kohana sprig
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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