Current latest version is 5.2.
Current latest LTS version is 5.1.
To install LTS version 5.1 using create-project command
[php]
composer create-project laravel/laravel blog "5.1.*"
[/php]
Another Kuantan Blogger
Current latest version is 5.2.
Current latest LTS version is 5.1.
To install LTS version 5.1 using create-project command
[php]
composer create-project laravel/laravel blog "5.1.*"
[/php]
Untuk create model dalam Laravel run command berikut
php artisan make:model Ticket
Note: a model name should be singular(Ticket), and a table name should be plural(tickets).
Selepas command berkenaan dilaksanakan, anda akan jumpa file model Ticket.php dalam direktori app/.
[php]
‘components’=>array(
…
‘mail’ => array(
‘class’ => ‘YiiMail’,
‘transportType’ => ‘php’,
‘transportType’ => ‘smtp’,
‘transportOptions’=>array(
‘host’=>’ghazalitajuddin.com’,
//’encryption’=>’tls’,
‘username’=>’***@ghazalitajuddin.com’,
‘password’=>’******’,
‘port’=>25,
),
‘logging’ => true,
‘dryRun’ => false
),
…
),
[/php]
[php]</pre>
$message = new YiiMailMessage;
$message->setBody($model->message);
$message->subject = $model->subject;
$message->addTo($model->to);
$message->from = Yii::app()->params[‘adminEmail’];
Yii::app()->mail->send($message);
<pre>[/php]
[php]
class EmailForm extends CFormModel
{
public $email;
public $to;
public $subject;
public $message;
public $from;
/**
* Declares the validation rules.
*/
public function rules()
{
return array(
// name, email, subject and body are required
array(’email, to, subject, message’, ‘required’),
// email has to be a valid email address
array(’email’, ’email’),
// verifyCode needs to be entered correctly
//array(‘verifyCode’, ‘captcha’, ‘allowEmpty’=>!CCaptcha::checkRequirements()),
);
}
/**
* Declares customized attribute labels.
* If not declared here, an attribute would have a label that is
* the same as its name with the first letter in upper case.
*/
public function attributeLabels()
{
return array(
‘verifyCode’=>’Verification Code’,
);
}
}
[/php]
[php]
<?php
$this->pageTitle=Yii::app()->name . ‘ – Email Others’;
$this->breadcrumbs=array(
‘Email’,
);
?>
<h1>Email others</h1>
<?php if(Yii::app()->user->hasFlash(’email’)): ?>
<div class="flash-success">
<?php echo Yii::app()->user->getFlash(’email’); ?>
</div>
<?php else: ?>
<p>
If you have business inquiries or other questions, please fill out the following form to contact us. Thank you.
</p>
<div class="form">
<?php $form=$this->beginWidget(‘CActiveForm’, array(
‘id’=>’email-form’,
‘enableClientValidation’=>true,
‘clientOptions’=>array(
‘validateOnSubmit’=>true,
),
)); ?>
<p class="note">Fields with <span class="required">*</span> are required.</p>
<?php echo $form->errorSummary($model); ?>
<div class="row">
<?php echo $form->labelEx($model,’email’); ?>
<?php echo $form->textField($model,’email’); ?>
<?php echo $form->error($model,’email’); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,’to’); ?>
<?php echo $form->textField($model,’to’); ?>
<?php echo $form->error($model,’to’); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,’subject’); ?>
<?php echo $form->textField($model,’subject’,array(‘size’=>60,’maxlength’=>128)); ?>
<?php echo $form->error($model,’subject’); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,’message’); ?>
<?php echo $form->textArea($model,’message’,array(‘rows’=>6, ‘cols’=>50)); ?>
<?php echo $form->error($model,’message’); ?>
</div>
<div class="row">
<?php echo $form->labelEx($model,’from’); ?>
<?php echo $form->textArea($model,’from’); ?>
<?php echo $form->error($model,’from’); ?>
</div>
<div class="row buttons">
<?php echo CHtml::submitButton(‘Submit’); ?>
</div>
<?php $this->endWidget(); ?>
</div><!– form –>
<?php endif; ?>
[/php]
Sample using CActiveDataProvider
Sample 1:
[php]
$dataProvider=new CActiveDataProvider(‘User’,array(
‘criteria’=>array(
‘condition’=>’activationstatus = 1’),
));
[/php]
Sample 2:
[php]
$dataProvider=new CActiveDataProvider(‘Event’, array(
‘criteria’=>array(
‘condition’=>’date >= "’.date(‘Y-m-d’, strtotime(‘-2 years’)).’"’,
),
));
[/php]
Sample 3:
[php]
$dataProvider=new CActiveDataProvider(‘Post’, array(
‘pagination’=>array(
‘pageSize’=>5,
),
‘criteria’=>$criteria,
));
[/php]
Sample 4:
[php]
$dataProvider=new CActiveDataProvider(‘User’)
[/php]
Some function is created to make code easy to read and manageable. The Lookup function is so powerfull to simplified data storage. Usually we store Approve, Not Approved, Qualified, Not Qualified in words for each records, but with Lookup class, we can make it short to an integer for each properties.
Table scheme “tbl_lookup”
[php]
CREATE TABLE tbl_lookup
(
id INTEGER NOT NULL PRIMARY KEY AUTO_INCREMENT,
name VARCHAR(128) NOT NULL,
code INTEGER NOT NULL,
type VARCHAR(128) NOT NULL,
position INTEGER NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COLLATE=utf8_unicode_ci;
[/php]
Insert some records like this
[php]
INSERT INTO tbl_lookup (name, type, code, position) VALUES (‘Activated’, ‘ActivationStatus’, 1, 1);
INSERT INTO tbl_lookup (name, type, code, position) VALUES (‘Not Activated’, ‘ActivationStatus’, 2, 2);
INSERT INTO tbl_lookup (name, type, code, position) VALUES (‘Pending Approval’, ‘membership_status’, 1, 1);
INSERT INTO tbl_lookup (name, type, code, position) VALUES (‘Approved’, ‘membership_status’, 2, 2);
INSERT INTO tbl_lookup (name, type, code, position) VALUES (‘Not Approved’, ‘membership_status’, 3, 3);
[/php]
/**
* Lists all models.
*/
public function actionIndex()
{
$dataProvider=new CActiveDataProvider(‘User’,
array(
‘pagination’=>array(
‘pageSize’=>10,
),
‘sort’=>array(
‘defaultOrder’=> array(‘id’=>false),
)
));
$this->render(‘index’,array(
‘dataProvider’=>$dataProvider,
));
}
[/php]