Skip to content
This repository has been archived by the owner on Oct 20, 2023. It is now read-only.

Commit

Permalink
\#51 using modelClass as model name in Controller in order to allow e…
Browse files Browse the repository at this point in the history
…xtending the plugin. Fixed Taggable Behavior to use Tag alias
  • Loading branch information
gmansilla committed Jan 27, 2014
1 parent cda3e47 commit 8e007c3
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
16 changes: 8 additions & 8 deletions Controller/TagsController.php
Expand Up @@ -52,7 +52,7 @@ class TagsController extends TagsAppController {
* @return void
*/
public function index() {
$this->Tag->recursive = 0;
$this->{$this->modelClass}->recursive = 0;
$this->set('tags', $this->Paginator->paginate());
}

Expand All @@ -64,7 +64,7 @@ public function index() {
*/
public function view($keyName = null) {
try {
$this->set('tag', $this->Tag->view($keyName));
$this->set('tag', $this->{$this->modelClass}->view($keyName));
} catch (Exception $e) {
$this->Session->setFlash($e->getMessage());
$this->redirect('/');
Expand All @@ -77,7 +77,7 @@ public function view($keyName = null) {
* @return void
*/
public function admin_index() {
$this->Tag->recursive = 0;
$this->{$this->modelClass}->recursive = 0;
$this->set('tags', $this->Paginator->paginate());
}

Expand All @@ -89,7 +89,7 @@ public function admin_index() {
*/
public function admin_view($keyName) {
try {
$this->set('tag', $this->Tag->view($keyName));
$this->set('tag', $this->{$this->modelClass}->view($keyName));
} catch (Exception $e) {
$this->Session->setFlash($e->getMessage());
$this->redirect('/');
Expand All @@ -103,7 +103,7 @@ public function admin_view($keyName) {
*/
public function admin_add() {
if (!empty($this->request->data)) {
if ($this->Tag->add($this->request->data)) {
if ($this->{$this->modelClass}->add($this->request->data)) {
$this->Session->setFlash(__d('tags', 'The Tags has been saved.'));
$this->redirect(array('action' => 'index'));
}
Expand All @@ -118,7 +118,7 @@ public function admin_add() {
*/
public function admin_edit($tagId = null) {
try {
$result = $this->Tag->edit($tagId, $this->request->data);
$result = $this->{$this->modelClass}->edit($tagId, $this->request->data);
if ($result === true) {
$this->Session->setFlash(__d('tags', 'Tag saved.'));
$this->redirect(array('action' => 'index'));
Expand All @@ -131,7 +131,7 @@ public function admin_edit($tagId = null) {
}

if (empty($this->request->data)) {
$this->request->data = $this->Tag->data;
$this->request->data = $this->{$this->modelClass}->data;
}
}

Expand All @@ -142,7 +142,7 @@ public function admin_edit($tagId = null) {
* @return void
*/
public function admin_delete($id = null) {
if ($this->Tag->delete($id)) {
if ($this->{$this->modelClass}->delete($id)) {
$this->Session->setFlash(__d('tags', 'Tag deleted.'));
} else {
$this->Session->setFlash(__d('tags', 'Invalid Tag.'));
Expand Down
10 changes: 5 additions & 5 deletions Model/Behavior/TaggableBehavior.php
Expand Up @@ -170,12 +170,12 @@ public function saveTags(Model $model, $string = null, $foreignKey = null, $upda
$existingTags = $tagModel->find('all', array(
'contain' => array(),
'conditions' => array(
$tagAlias . '.keyname' => Set::extract($tags, '{n}.keyname')),
$tagModel->alias . '.keyname' => Set::extract($tags, '{n}.keyname')),
'fields' => array(
$tagAlias . '.identifier',
$tagAlias . '.keyname',
$tagAlias . '.name',
$tagAlias . '.id'
$tagModel->alias . '.identifier',
$tagModel->alias . '.keyname',
$tagModel->alias . '.name',
$tagModel->alias . '.id'
)
));

Expand Down

0 comments on commit 8e007c3

Please sign in to comment.