Earthtracker's Blog

Just another WordPress.com weblog

CakePHP 3 Sending Email

public function sendemail($to,$from,$from_name,$subject,$message)
    {
        Email::configTransport('SMTP', [
            'host' => 'ssl://mail.xxxx.com',
            'port' => 465,
            'username' => 'xx@xxxxx.com',
            'password' => 'password',
            'className' => 'Smtp'
        ]);
        $email = new Email();
        $email->transport('SMTP');
        $email->from([$from => $from_name])
            ->to($to)
            ->subject($subject)
            ->send($message);
    }
Advertisements
Leave a comment »

Enable SSL for virtual host on Apache windows

<VirtualHost *:443>
    ServerName local.miraiinsiders.com

    DocumentRoot D:/xampp/htdocs/miraiinsiders/content/
    #ErrorLog /var/www/example.com/error.log
    #CustomLog /var/www/example.com/requests.log combined
    SSLEngine on
    SSLCertificateFile "conf/ssl.crt/server.crt"
    SSLCertificateKeyFile "conf/ssl.key/server.key"
</VirtualHost>
Leave a comment »

CakePHP3 Add Datetime for Created / Modified field

$data['created']=new \DateTime('now');
Leave a comment »

CakePHP3 JoinWith passing variables to callback function

Cakephp3 Join: Passing parameters to Call Back Function

function findResult($xx_id)
{
    $res = $this->Model1
                ->find()
                ->select(['Model1.col_name', 'Model2.col_name'])
                ->leftJoinWith('Model2', function ($q) use ($xx_id) {
                    return $q->where(['Model1.xx_id' => $xx_id);}
                );
}
Leave a comment »

Configure Virtual Host on XAMPP/WAMPP and access from another PC

This will demonstrate to configure Virtual host on windows PC and access it from another PC.

Open hosts file from \Windows\System32\drivers\etc using Notepad as Administrator

Write the following code:

127.0.0.1  xxxx.local

Note:xxxx.local your domain or subdomain name

For XAMPP:
Open httpd-vhosts.conf from xampp\apache\conf\extra

For WAMPP:
Open httpd-vhosts.conf from wamp\bin\apache\apache2.4.9\conf\extra

Write the following code :

<VirtualHost 127.0.0.1>
    ##ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "D:/xampp/htdocs/xxxx/"
    ServerName xxxx.local
    
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

To use the virtual host from another PC

<VirtualHost xxx.xxx.xxx.xxx:80>
    ##ServerAdmin webmaster@dummy-host2.example.com
    DocumentRoot "D:/xampp/htdocs/xxx/"
    ServerName xxxx.local
    <Directory "/">
   # Deny from all
    Allow from  xxx.xxx.xxx.xxx
    Allow from  127.0.0.1
    </Directory>
    ##ErrorLog "logs/dummy-host2.example.com-error.log"
    ##CustomLog "logs/dummy-host2.example.com-access.log" common
</VirtualHost>

Note:
xxx.xxx.xxx.xxx:80 : local pc IP and port
Allow from xxx.xxx.xxx.xxx : IP of the another PC from where you like to access the Virtual host
If you like to allow it from all , use :

    Allow from  all 

Retstart XAMPP / WAMPP

Enjoy!

Leave a comment »

CakePHP3 created modified not added automatically

Created / Modified should be added automatically.
if not, please check you used following behavior in Model->Table:

public function initialize(array $config)
{
$this->addBehavior(‘Timestamp’);
}

Leave a comment »

Replace url segment or folder with htaccess

If you like to replace a url segment or folder , you can follow :

https://www.example.com/loren/lipsum/blog_title
to
https://www.example.com/loren/sepcticula/blog_title

RewriteEngine On
RewriteRule ^/?loren/lipsum/(.*)$ https://www.example.com/loren/sepcticula/$1 [R=301,L]
Leave a comment »

PHP version issue when installing Craft 3 using Composer

To Ignore the PHP version warning on Craft 3 installation, need to use –ignore-platform-reqs
like

create-project -s RC craftcms/craft PATH --ignore-platform-reqs
Leave a comment »

Change Domain root to specific folder

write htaccess file on current root.

RewriteCond %{REQUEST_URI} !domain/
RewriteRule (.*) /folder/$1 [L]

Leave a comment »

শহিদ আজাদ এর মা কে নিয়ে লিখা আনিসুল হক এর মা উপন্যাস

Download Maa-Anisul-hoq

Leave a comment »