Reputation: 5820
I have a model called Emails, which I have build a lot 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).
P.S. I'm used to rails so I thought it would be called notifier.
Upvotes: 4
Views: 629
Reputation: 522510
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->...
}
Upvotes: 5
Reputation: 21563
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).
Upvotes: 1
Reputation: 6360
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 ;)
Upvotes: 0
Reputation: 4604
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.
Upvotes: 0