Skip to content

Commit

Permalink
Setting default controller id if not supplied
Browse files Browse the repository at this point in the history
  • Loading branch information
motin committed Jul 29, 2013
1 parent e43ff00 commit ccee491
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions fullCrud/FullCrudCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,8 +115,30 @@ public function requiredTemplates()
);
}

protected function defaultControllerId($model)
{
// Return default controller Id
// Based on javascript code from gii frontend
preg_match('/^\w* /', $model, $matches);
$module = isset($matches[0]) ? $matches[0] : null;
preg_match('/\w*$/', $model, $matches);
$id = isset($matches[0]) ? $matches[0] : null;
if (strlen($id) > 0) {
$id = strtolower(substr($id, 0, 1)) . substr($id, 1);
}
if (strpos($model, ".") !== false && strpos($model, "application.") === false) {
$id = $module . "/" . $id;
}
return $id;

}

public function prepare()
{
if (!$this->controller) {
$this->controller = $this->defaultControllerId($this->model);
}

if (!$this->identificationColumn) {
$this->identificationColumn = $this->tableSchema->primaryKey;
}
Expand Down

0 comments on commit ccee491

Please sign in to comment.