CakePHP, an email model and email component. I did something stupid

I have a model called "Email" for which I have many functions, but now I have come to send email to the email controller and hit the wall.

The email component encounters a model that both reference $ this-> Email.

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

PS I'm used to the rails, so I thought it would be called a notifier.

+4
source share
4 answers

You can simply rename the EmailComponent component:

/controllers/components/email_handler.php:

App::import('Component', 'Email'); class EmailHandlerComponent extends EmailComponent { } 

Controller:

 public $components = array('EmailHandler'); public function foo() { $this->EmailHandler->... } 
+5
source

I would just use sed . Making sure the latest version is safe in VCS, a command like

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

performed in the appropriate directories should do the trick. I think you might also need to follow the alter/modify table instructions to rename the table (I'm not sure how Cake handles this since I haven't used it before).

+1
source

I walked a bit through the Controller API and I'm sure there is no workaround for your name conflict. As tedious and time consuming as it may be, you are probably better off biting a bullet and renaming your model. If nothing else, this is a more convenient and reliable approach, and it will probably pay off ten times along the line.

0
source

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

Search / Refusal may also come in handy as a last resort.

As a programmer, never rename manually;)

0
source

All Articles