views:

48

answers:

4

Hi.

I've been silly.

I have a model called Emails, which I have build alot of functionality for, however now I have come to actually send emails in the emails controller and have hit a wall.

The email component clashes with the model, they are both referenced with $this->Email.

My question is how can I rename the component (going back and changing the model would be a lot of work).

Cheers.

P.S. I'm used to rails so I thought it would be called notifier.

A: 

I went through the Controller class's API a bit, and I'm pretty sure there isn't a simple workaround to your naming conflict. As tedious and time-consuming as it may be, you're probably better off biting the bullet and renaming your model. If nothing else, it's the more maintainable and robust approach, and doing so will probably pay off ten-fold down the line.

Daniel Wright
A: 

Using an IDE (NetBeans for example) can make your life a lot easier. It has features like refactor/rename where it even tries to rename references it other files.

Search/Repalce might also come handy as a last resort.

As a programmer, never rename manually ;)

sibidiba
+1  A: 

I'd probably just use sed. After making sure the most recent version is safely in a VCS, a command like

sed 's/$this->Email/$this->Notification/' -i *php

executed in the relevant directories should do the trick. I guess you might also have to execute alter/modify table statements to rename the table (I'm not sure how Cake deals with that as I haven't used it before).

Alex JL
+3  A: 

You can just rename the EmailComponent:

/controllers/components/email_handler.php:

App::import('Component', 'Email');

class EmailHandlerComponent extends EmailComponent { }

Controller:

public $components = array('EmailHandler');

public function foo() {
    $this->EmailHandler->...
}
deceze
Brilliant, have a bicky.
Smickie
If Smickie's handing out bickies, I'm going to have to upvote this one.
Alex JL