Skip to content

Instantly share code, notes, and snippets.

View jamband's full-sized avatar
👀
web browser

Tomoki Morita jamband

👀
web browser
View GitHub Profile
<?php
class ItemController extends Controller
{
...
/**
* Creates a new item.
*/
public function actionCreate()
{
<div class="form">
<?php if ($item->scenario !== 'update'): ?>
<?php echo CHtml::statefulForm('', 'post', array('enctype' => 'multipart/form-data')); ?>
<?php echo CHtml::hiddenField('MAX_FILE_SIZE', '1000000'); ?>
<?php else: ?>
<?php echo CHtml::statefulForm(); ?>
<?php endif; ?>
<?php echo CHtml::errorSummary($item); ?>
<div class="form">
<?php if ($item->scenario !== 'update'): ?>
<?php echo CHtml::statefulForm('', 'post', array('enctype' => 'multipart/form-data')); ?>
<?php echo CHtml::hiddenField('MAX_FILE_SIZE', '1000000'); ?>
<?php else: ?>
<?php echo CHtml::statefulForm(); ?>
<?php endif; ?>
<?php echo CHtml::errorSummary($item); ?>
@jamband
jamband / Hoge.php
Last active March 10, 2017 11:32
Yii Framework: pagination and searching
<?php
class Hoge extends CActiveRecord
{
...
/**
* Gets the all models.
* @param string $q
* @return array
*/
public function getAll($q)
@jamband
jamband / Hoge.php
Last active October 10, 2016 11:21
Yii Framework: CListView and searching
<?php
class Hoge extends CActiveRecord
{
...
public function getAll($q)
{
$c = new CDbCriteria();
$c->addSearchCondition('t.fuga', $q);
return new CActiveDataProvider(get_class($this), array(
@jamband
jamband / sample.php
Last active September 28, 2015 12:28
Yii Framework: Send mail Japanese.
<?php
/* protected/config/main.php
-----------------------------------------------------------*/
return array(
...
'components' => array(
'mailer' => array(
'class' => 'ext.mailer.EMailer',
'CharSet' => 'iso-2022-jp',
@jamband
jamband / Item.php
Last active September 28, 2015 13:18
Yii Framework: Upload a file using a model.
<?php
class Item extends CActiveRecord
{
const ALLOW_TYPES = 'jpg, png, gif';
public $image;
...
/**
@jamband
jamband / sample.php
Last active August 19, 2016 23:14
Yii Framework: example LIKE query.
<?php
$c = new CDbCriteria();
Hoge::model()->findAll($c);
// SELECT * FROM `hoge` `t`
$c = new CDbCriteria();
$c->addSearchCondition('t.fuga', null); // null, false, ''などは無視されるようです
Hoge::model()->findAll($c);
@jamband
jamband / Forum.php
Last active December 29, 2015 17:12
Yii Framework: How to specify a column alias.
<?php
class Forum extends ActiveRecord
{
public $max_number;
public $max_create_time;
...
public function getLatestAll()
{
$c = new CDbCriteria();
@jamband
jamband / A.php
Last active September 28, 2015 18:38
Yii Framework: get/set methods and others.
<?php
class A
{
private $test;
public function __get($name)
{
$getter = 'get' . $name;
if (method_exists($this, $getter)) {
return $this->$getter();