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 HogeController extends Controller
{
/**
* 単純な単一フィールド更新の例
*/
public function actionIsChecked($id)
{
Hoge::model()->updateByPk($id, array('checked' => 1);
...
<?php
public function actions()
{
return array(
'update' => array(
'class' => 'application.components.actions.UpdateAction',
'redirect' => 'index', // この行を追加
),
);
...
<?php
class HogeController extends Controller
{
...
public function actions()
{
return array(
// アクション名を指定 ( actionUpdateとなる )
'update' => array(
'class' => 'application.components.actions.UpdateAction', // パス名指定
<?php
class UpdateAction extends CAction
{
/**
* リダイレクト先
*/
public $redirect = 'view';
public function run($id)
{
@jamband
jamband / main.php
Last active September 28, 2015 10:38
<?php
...
'components' => array(
'db' => array(
'enableProfiling' => true, // 追加
...
),
'log' => array(
'class' => 'CLogRouter',
'routes' => array(
@jamband
jamband / index.php
Last active September 28, 2015 10:38
<?php $this->widget('CLinkPager', compact('pages')); ?>
<?php echo CHtml::encode('結果数: ' . $pages->itemCount . ' 件'); ?>
<?php foreach ($models as $model): ?>
<div class="view">
<?php echo CHtml::encode($model->fuga); ?>
<?php echo CHtml::encode($model->piyo); ?>
<br />
</div><!-- /.view -->
<?php endforeach; ?>
<?php
class HogeController extends Controller
{
/**
* Lists all models.
*/
public function actionIndex()
{
list($pages, $models) = Hoge::model()->getAll();
$this->render('index', compact('pages', 'models'));
@jamband
jamband / Hoge.php
Last active September 28, 2015 10:38
<?php
class Hoge extends CActiveRecord
{
...
/**
* @see CActiveRecord::scopes()
*/
public function scopes()
{
return array(
<?php
class HogeController extends Controller
{
public function actions()
{
return array(
'edit' => array(
'class' => 'actions.EditAction',
//'class' => 'EditAction', // import に追加している場合
),
<?php
class HogeController extends Controller
{
public function actions()
{
return array(
'edit' => array(
'class' => 'application.components.actions.EditAction'
),
'delete' => array(