I am using PHP Mailer and i have mail function in app Controller and i want to access it in shell file for crone job.
anyone can guide me how to do this?
Thanks
I am using PHP Mailer and i have mail function in app Controller and i want to access it in shell file for crone job.
anyone can guide me how to do this?
Thanks
Sorry this is so late but if this were here before it would have helped me, so for future viewers:
Borrowing from a slightly different circumstance at CakePHP: best way to call an action of another controller with array as parameter? :
This is working for me so far (Haven't tried more complicated things in a controller yet): In .../app/Console/Command/BillsShell.php:
App::import('Controller', 'Billing');
class BillsShell extends AppShell {
public function main() {
$billing = new BillingController();
$billing->constructClasses(); //I needed this in here for more complicated requiring component loads etc in the Controller
$billing->test();
}
}
In BillingController.php:
class BillingController extends AppController {
function test() {
echo "****Big test!!!*****\n\n";
}
}
For cake 2.1.3:
$> .../app/Console/php cake.php bills
Welcome to CakePHP v2.1.3 Console
---------------------------------------------------------------
App : app
Path: .../app/
---------------------------------------------------------------
****Big test!!!*****
You should use Cakephp Shell in order to do something in cron. The question was talked in How to setup cronjobs in cake php? .
EDIT: If you need to use something both in your controller and shell, I would suggest to move it to component. In your shell you can do
App::import('Component', 'Meteor');
$this->Meteor = new MeteorComponent();
$this->Meteor->flash('New York');
In controller
$components = array('Meteor');
public function your_action() {
// code
$this->Meteor->flash('Paris');
}
It is:
App::uses('CakeRequest', 'Network');
App::uses('CakeResponse', 'Network');
App::uses('Controller', 'Controller');
App::uses('AppController', 'Controller');
$controller = new AppController(new CakeRequest(), new CakeResponse());
=> $controller is yours
There seems no direct method to call Controller inside Shell official document, where as we can do a work around, where we can call Model from Shell and in the Model we can call Controller.
Shell:
public function main() {
App::import('Model', 'UserModel');
$this->UserModel = ClassRegistry::init('UserModel');
$this->UserModel->callModel();
}
Model:
function callModel($created) {
App::import('Controller', 'Pages');
$something = new PagesController;
$something->callMe();
}
Controller:
public function callMe(){
echo "Finally, Controller method is called\n";
}
FYI: Its just a work around.