English 中文(简体)
• 如何在面包所从事 cr工作?
原标题:how to perform cron job in cakephp?
  # Cron Job for Cakephp #

我建立了1个档案文件,即:wamp/www/projectname/app/webroot/index.php,而且档案也属于同一文件夹。

i have tried to run throw command prompt but didn t get any result.

how to run cronjob for Cakephp ? i don t have any idea if anyone knows , please help me. Thanks in advance.


 <?php
    if (!defined( DS )) {
            define( DS , DIRECTORY_SEPARATOR);
    }
   /**
      * These defines should only be edited if you have cake installed in
      * a directory layout other than the way it is distributed.
      * Each define has a commented line of code that explains what you
        would change.
      *
      */
        if (!defined( ROOT )) {
            //define( ROOT ,  FULL PATH TO DIRECTORY WHERE APP DIRECTORY IS
            //LOCATED DO NOT ADD A TRAILING DIRECTORY SEPARATOR ;
            //You should also use the DS define to seperate your directories
            define( ROOT , dirname(dirname(__FILE__)));
    }
    if (!defined( APP_DIR )) {
            //define( APP_DIR ,  DIRECTORY NAME OF APPLICATION ;
            define( APP_DIR , basename(dirname(__FILE__)));
    }
      /**
        * This only needs to be changed if the cake installed libs are located
        * outside of the distributed directory structure.
       */
           if (!defined( CAKE_CORE_INCLUDE_PATH ))
              {
            //define ( CAKE_CORE_INCLUDE_PATH , FULL PATH TO DIRECTORY WHERE
            //CAKE CORE IS INSTALLED DO NOT ADD A TRAILING DIRECTORY SEPARATOR ;
             //You should also use the DS define to seperate your directories
             define( CAKE_CORE_INCLUDE_PATH , ROOT);
              }

            ///////////////////////////////
            //DO NOT EDIT BELOW THIS LINE//
            ///////////////////////////////

            if (!defined( WEBROOT_DIR )) 
             {
            define( WEBROOT_DIR ,  webroot );
    }
    if (!defined( WWW_ROOT )) {
            //define( WWW_ROOT , dirname(__FILE__) . DS);
            define( WWW_ROOT , dirname(__FILE__) . DS .  webroot  . DS);
    }
    if (!defined( CORE_PATH )) {
            if (function_exists( ini_set )) {
                    ini_set( include_path , CAKE_CORE_INCLUDE_PATH . 
                    PATH_SEPARATOR .
                    ROOT . DS . APP_DIR . DS . PATH_SEPARATOR . ini_get( include_path ));
                    define( APP_PATH , null);
                    define( CORE_PATH , null);
            } else {
                    define( APP_PATH , ROOT . DS . APP_DIR . DS);
                    define( CORE_PATH , CAKE_CORE_INCLUDE_PATH . DS);
            }
    }
    require CORE_PATH .  cake  . DS .  bootstrap.php ;


    define( CRON_DISPATCHER ,true);
    if($argc == 2) 
    {
            $Dispatcher= new Dispatcher();
            $Dispatcher->dispatch($argv[1]);
    }

          ?>

> i have tried to run throw command promt but didn t get any result 
> how to run cronjob for Cakephp ? i don t have any idea
  if anyone knows , please help me.
  Thanks 
问题回答

Step1: Create a shell file with name ReminderShell.php and Path should be PROJECT_DIR_PATH/PROJECT_NAME/app/Console/Command/ReminderShell.php Copy below script and paste it

class ReminderShell extends Shell { 
         var $tasks = array( Mail ); 
         function main() { 
               $this->Mail->enroll_reminder(); 
                         }
          }

步骤2: 任务文件,名称为《邮局》。 php和途径应当是PROJECT_DIR_PATH/PROJECT_NAME/app/Console/Command/Task/mailTask.php

<?php

App::uses( CakeEmail ,  Network/Email );

class MailTask extends Shell {

var $uses = array( Contact );

public function enroll_reminder() {
    $Email = new CakeEmail();
    $Email->config( default );
    $reminder = $this->Contact->find( all );
    if (!empty($reminder)) {
        foreach ($reminder as $val) {
        $id = $val[ Contact ][ id ];
        $name = $val[ Contact ][ first_name ];
        $email = $val[ Contact ][ email ];
        $Email->template( reminder )
            ->viewVars(array( fname  => $name))
            ->emailFormat( html )
            ->subject( xyz.com: Enrollment Reminder )
            ->to($email)
            ->from( [email protected] );
        if ($Email->send()) {
            $update_val[ Contact ][ id ] = $id;
            $update_val[ Contact ][ enroll_reminder ] =  sent ;
            $update_val[ Contact ][ enroll_reminder_date ] = date("Y-m-d H:i:s");
            $this->Contact->save($update_val[ Contact ]);
            $this->out($email.  Mail Sent );
        }
        }
    }
}

步骤3:建立附有姓名提示的电子邮件模板,时间和途径应是PROJECT_DIR_PATH/PROJECT_NAME/app/View/Emails/html/reminder.ctp

步骤4:建立电子邮件。 电池组

Step5: Run below command in Terminal: Console/cake Reminder

PROJECT_DIR_PATH/PROJECT_NAME/app Console/cake Reminder 

https://github.com/pankajkumarjha2010/cronjob-in-cakephp2.3.x”rel=“nofollow”https://github.com/pankajkumarjha2010/cronjob-in-cakephp2.3.x





相关问题
performance improvements in CakePHP 2.0?

Can anyone attest to performance improvements in the upcoming CakePHP 2.0? I m facing a decision on a project: to go with current release of CodeIgniter or start with Cake and upgrade later to 2.0. ...

Save data in MongoDB subdocument with CakePHP

In CakePHP I am trying to save data in a subdocument like this: $mongo = $this->User->getDataSource(); $mongo->update($this->User, array( array( _id => $tweep[ User ]...

How do I use datasources in CakePHP 2?

My MongoDB datasource is located in plugins/mongodb. According to the new class loader in 2.0 I should do this: App::uses( MongodbSource , Mongodb.Model/Datasource ); But how do I initiate it? Or ...

FULL TEXT SEARCH in cakephp ? any example

I am using ordinary search functionality in my business controller . but now need to implement FULL TEXT SEARCH with paginate can any one give idea or sample ? I am using MySQL with MyISAM tabes ...

Themes in CakePHP 2.0.0-dev

Trying to set up a mobile theme in CakePHP 2.0.0-dev, but it isn t working as it did in 1.3. Have there been any changes to the themes implementation in 2.0? Structure as follows: app/views/themed/...

cakephp 2.0 features?

where can i read more about cakephp 2.0 features? cause i could find symfony 2.0 presentations but not for cakephp 2.0 thanks

Retrieve value from an Array in Cakephp

I am trying to get some data to display from an Array in Cakephp, the Array has all the data from a find() output and other parts of the data output fine. The data i am trying to access is the name ...

热门标签