Posts Tagged with yii

Displaying 101-110 of 113 results.
Wiki: Yii - пример создания виджета - widget example - шаблон для контроллераwiki
posted by admin on January 22, 2016
Итак - вот мой контроллер - он лежит в папке /protected/components

<?php
/* рассмотрим здесь "параметризированный" виджет*/
class AdminMenuWidget extends CWidget {

/*в общем случаем может
хранить целый массив свойст - нас же интересует
только текущее действие
- чтобы подсветить активный элемент меню*/
public $params = array(
// пусть по умолчанию будет активна ссылка на главную
'action'=>'index',
// следующие два не использую - просто для примера
'parameter 2'=>'value 2',
'parameter 3'=>'value 3',
);

public function run() {
// передаем данные в представление виджета
$this->render('adminmenu',array('params' => $this->params));
}
}


представление контроллера для этого вижжета лежит рядом - а именно так -

/protected/components/views


и выглядит так:

< ul class="nav nav-pills" >
< li<?php if ($params['action']=='index')
echo ' class="active"' ;
?>>
<?php echo CHtml::link('Админка', array('perfomance/index')); ?>
< /li >

< li<?php if ($params['action'] == 'showtickets')
echo ' class="active"' ;
?>>
<? php echo CHtml::link('Заявки', array('perfomance/showtickets')); ?>
< /li >

< li<?php if ($params['action'] == 'rebuildroles')
echo ' class="active"' ;
?>>
<?php echo CHtml::link('Роли', array('perfomance/rebuildroles')); ?> < /li >
</ul>


Как отобразить виджет
Это просто - например в представлении некоего контроллера я пишу:

<?php
$this->beginWidget('AdminMenuWidget',array(
'params'=>array(
//получаем текущее действие чтобы подсветить активный элемент меню
'action' => Yii::app()->getController()->getAction()->getId(),
)));
$this->endWidget();
?>
Read more
Wiki: Yii 1.1: Archive Yearly and Monthly in Blog systemwiki
posted by admin on January 22, 2016
Hi I had made simple archive system for blog system that can handle tbl_post. I had used simple CDbCriteria not more than that. I know there is more and many better way to this but I think this will give some idea to users to generate new idea or customized or modified this version of code.


//in module define

public $year;
public $month;


In controller controller of view you can use this. I had used here view for testing.

<?php
$monthsvalue = array('1'=>'January','2'=>'Feburary','3'=>'March','4'=>'April','5'=>'May','6'=>'June','7'=>'July','8'=>'August','9'=>'September','10'=>'October','11'=>'November','12'=>'December');


$condition = new CDbCriteria;
$condition->select='YEAR(t.createddate) as year'; //declare year in post model model
$condition->distinct=true;
$condition->order ='createddate DESC';

$yeardataarticle = Post::model()->findAll($condition);

foreach ($yeardataarticle as $ya):
$year =$ya->year;
echo '
';
echo $year;
$monthcriteria = new CDbCriteria;
$monthcriteria->select ='MONTH(t.createddate) as month'; // declare month in post model
$monthcriteria->condition ='YEAR(t.createddate)=:year';
$monthcriteria->params=array(':year'=>$year);
$months = Post::model()->findAll($monthcriteria);
foreach ($months as $month):


$montth = $month->month;
echo '
';

foreach($monthsvalue as $key=>$value):

if (!isset(${'printed'.$key.$year})) ${'printed'.$key.$year} = false;

//var_dump('printed'.$key.$year);exit;

if($key==$montth and !${'printed'.$key.$year}){

echo CHtml::link($value,array('//post/archivepost','year'=>$year,'month'=>$montth));
${'printed'.$key.$year}=true;

$postcount = new CDbCriteria;
$postcount->addCondition('MONTH(t.createddate)=:month AND YEAR(t.createddate)=:year');
$postcount->params = array(':month'=>$montth,':year'=>$year);
$count = Post::model()->count($postcount);
echo ' ('.$count.')';
}

endforeach;

endforeach;

endforeach;
?>
Read more
Resolved: Yii form dropDownList create and update support example with empty first option
posted by admin on January 22, 2016
I have form on yii. It is news form. I want to change news category by select box and in update form have selected option.Read more
Resolved: Yii admin module link url default
posted by admin on January 21, 2016
I create admin module, and try to open link http://localhost/test/admin , and get 404 error, object not found.Read more
Resolved: Yii gii object not found
posted by admin on January 21, 2016
I try to open http://localhost/test/gii , and get error
Error 404
object not foundRead more
Resolved: Yii captcha does not work first time
posted by admin on December 22, 2015
I am trying to create register form where I used captcha. I have enabled ejax validation. But the there is a problem, captcha does not work first time. When I generate new captcha code, that works. My code is:

In model,

public $verifyCode;

public function rules()
{
return array(
array('verifyCode','captcha','allowEmpty'=>!CCaptcha::checkRequirements(), 'on'=>'registration'),

array('id, first_name,last_name, email, username, password, password_repeat, user_type, keystring, status, logo_url, last_login_time, create_time, update_time, validation', 'safe', 'on'=>'search'),
);
}

In controller:

public function actions()
{
return array(
'captcha'=>array(
'class'=>'CCaptchaAction',
'backColor'=>0xFFFFFF,
'testLimit'=>3,
),
);
}

In view:

<?php if(CCaptcha::checkRequirements()): ?>
<div class="row">
<?php echo $form->labelEx($model,'verifyCode'); ?>
<?php $this->widget('CCaptcha', array('captchaAction'=>'user/captcha')); ?>
</div>
<div class="formfieldarea">
<div class="form-text"></div>
<div class="form-field">
<?php echo $form->textField($model,'verifyCode'); ?>
<div class="hint">Please enter the letters as shown.

Letters are not case-sensitive.</div>
<?php echo $form->error($model,'verifyCode'); ?>
</div>
</div>
<?php endif; ?>

I have searched in google a lot to find the solution. But did not find. Please help someone.:(Read more
Resolved: yii session_regenerate_id(): Session object destruction failed
posted by admin on January 17, 2016
I got an error, when trying to login without checking REMEMBER ME.Read more
Resolved: Yii - How to customize a CGridView CbuttonColumn
posted by admin on December 25, 2015
Customize default buttons? :(Read more
Resolved: Yii 1.1: syntaxhighlighter extension CListView ajax pagination problem
posted by admin on December 25, 2015
CListView ajax pagination Can't find XML Brush etc.
First page working great, but when working ajax pagination, brushes not working, not finding any brushes.

My code:

<?php Yii::app()->syntaxhighlighter->addHighlighter(); ?>
Read more
Resolved: How To Set The "pagevar" Parameter For The Grid View Widget?
posted by admin on December 25, 2015
Hi,
I have a gridview widget:

$this->widget('zii.widgets.grid.CGridView', array(
'dataProvider' => $model->search(),
'summaryText' => 'صفحه {page} از مجموع {pages} صفحه',
'enableSorting' => false,
'enablePagination' => true,
'ajaxUpdate' => false,
'columns'=>array(
//....
),
));


In the pagination links it includes the model name as prefix to pageVar parameter. is there anyway to set the pageVar property of widget so it changes the links from "index.php?r=item/list&Items_page=2" to "index.php?r=item/list&page=2" ?Read more