Displaying 11-20 of 268 results.
Wiki: Yii2 basic include css js files to module views layout main from module assetswiki
posted by admin on March 1, 2017
Module Information
Module Admin

app/modules/admin/Module.php
app/modules/admin/views/default/index.php

Create Module ASSETS in Web folder with content

app/modules/admin/web/assets/css/style.css
app/modules/admin/web/assets/js/main.js

Create Module views layouts

app/modules/admin/views/layouts/main.php

Change your Module and change layouts way in your config web.php

<?php
$config = [
'id' => 'basic',
'basePath' => dirname(__DIR__),
'bootstrap' => ['gii'],
'modules' => [
'gii' => [
'class' => 'yii\gii\Module',
'allowedIPs' => ['127.0.0.1', '::1', '192.168.0.*', '192.168.178.20'] // adjust this to your needs
],
'admin' => [
'class' => 'app\modules\admin\Module',
// the layout that should be applied for views within this module
'layout' => 'main',
],
],
...........

Create Module new assets settings class
In modules/admin directory create file AdminAsset.php with content

<?php
namespace app\modules\admin;
use yii\web\AssetBundle;

class AdminAsset extends AssetBundle
{
public $sourcePath = '@app/modules/admin/web/assets';
public $css = [
'css/style.css',
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap\BootstrapAsset',
];
}

Go to your Admin Module layouts/main.php and replace your assets registration and namespace with

use app\modules\admin\AdminAsset;

AdminAsset::register($this);
Read more
Resolved: Yii2 basic render path problem in modules
posted by admin on March 1, 2017
In my layouts I have code with render

. . .
<div class="wrap">
<?= $this->render('/partials/menu'); ?>
</div>
. . .

And when I run my Module I have got error

The view file does not exist: The view file does not exist: /var/www/html/vktracker2/modules/admin/views/partials/menu.php

I tried to fix by

<?= $this->render(dirname(_FILE__) . '/partials/menu'); ?>

But it didn't helpRead more
Resolved: Yii2 Gii Module Generator error
posted by admin on March 1, 2017
Error Message:

yii2 module generator gii There was something wrong when generating the code. Please check the following messages.

Wrong operations

Generating code using template "/home/ssdd/app/etp.loc/app/vendor/yiisoft/yii2-gii/generators/module/default"...
generating modules/admin/Module.php
Unable to create the directory '/home/ssdd/app/etp.loc/app/frontend/modules/admin'.
generating modules/admin/controllers/DefaultController.php
Unable to create the directory '/home/ssdd/app/etp.loc/app/frontend/modules/admin/controllers'.
generating modules/admin/views/default/index.php
Unable to create the directory '/home/ssdd/app/etp.loc/app/frontend/modules/admin/views/default'.
done!
Read more
Wiki: Install Notepad ++ on Ubuntu 16.04wiki
posted by admin on February 28, 2017
To add the PPA, update apt-get and run install - open terminal (Ctrl+Alt+T) and run:

sudo add-apt-repository ppa:notepadqq-team/notepadqq
sudo apt-get update
sudo apt-get install notepadqq
Read more
Wiki: PHPStorm FIX - not working hotkey CTRL + keys functionalitywiki
posted by admin on February 27, 2017
In most java-application with a GUI on Ubuntu in Russian layout is not working hotkeys, even the standard Ctrl + C and Ctrl + V. But a good man, named Michael Zheludkov wrote fix this bug, for which he had great thanks.
Installation
Clone repository in the folder ~ / fix /:

git clone https://github.com/zheludkovm/LinuxJavaFixes.git fix

Открываем конфиг приложения: or edit with GEDIT editor

nano /opt/PhpStorm/bin/phpstorm64.vmoptions

Add the following line to the fix:

-javaagent:/home/{user}/fix/build/LinuxJavaFixes-1.0.0-SNAPSHOT.jar

Replace {user} to your Ubuntu user UsernameRead more
Wiki: Yii2 behavior and beforeSave usage example without conflicts and errorswiki
posted by admin on February 22, 2017
Behaviors:

public function behaviors()
{
return [
[
'class' => TimestampBehavior::className(),
'createdAtAttribute' => 'created_dt',
'updatedAtAttribute' => 'updated_dt',
'value' => your datetime format value,//or remove row to default with UNIX TIMESTAMP
],
];
}

BeforeSave:

public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {

if ($this->isNewRecord){
//to do
}else{
//to do
}

return true;
}
return false;
}
Read more
Wiki: Yii2 beforeSave() and afterSave()wiki
posted by admin on February 22, 2017
Wonderful methods beforeSave () and afterSave () in Yii2 help us to solve various problems, for example, you want before saving the database to change the date format, or save the log action. But not everyone knows how to inherit them.

Let's start with a simple afterSave():

public function afterSave($insert, $changedAttributes){
parent::afterSave($insert, $changedAttributes);
//... to do
}

There is nothing complicated, we simply pass to the parent method all the same settings and run it, and then do everything we needed.

Now beforeSave():

public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
//... to do
return true;
}
return false;
}

All the practical as well as with afterSave() method, except that we need to return the result of the parent method, otherwise we when calling $model->save() will get false, and our model will not be saved, nor do we we will receive no errors. Remember this moment.

Yii1 The principle is the same, only the parameters are not transferred there.Read more
Resolved: Yii2 Class 'app\models\TimestampBehavior' not found
posted by admin on February 21, 2017
I have User model and have behavior in model

<?php

namespace app\models;

use Yii;
use yii\base\NotSupportedException;
use yii\db\ActiveRecord;
use yii\helpers\Security;
use yii\web\IdentityInterface;
use app\helpers\Table;
use app\helpers\App;
/**
* This is the model class for table "tbl_user".
*
* @property integer $id
* @property string $username
* @property string $password
* @property string $email
* @property integer $role_id
* @property integer $user_id
* @property integer $status_id
* @property integer $created_dt
* @property integer $updated_dt
* @property integer $timezone_id
*/
class User extends \yii\db\ActiveRecord implements IdentityInterface
{
public $authKey;
public $accessToken;

/**
* @inheritdoc
*/
public static function tableName()
{
return '{{%'.Table::$user.'}}';
}

public function behaviors()
{
return [
'timestamp' => [
'class' => TimestampBehavior::className(),
'attributes' => [
ActiveRecord::EVENT_BEFORE_INSERT => 'creation_time',
ActiveRecord::EVENT_BEFORE_UPDATE => 'update_time',
],
'value' => function() { return App::datetime_now_unix(); },
],
];
}
. . .
}

Error

Class 'app\models\TimestampBehavior' not found
Read more
Resolved: Yii2 required rule not show red star(asterisk) symbol
posted by admin on February 21, 2017
I have form and I have required fields
In output not showing red asterisk(star).
How to resolve it?Read more
Resolved: Yii2 NavBar check isGuest leave empty or fill with multiple items
posted by admin on February 21, 2017

<?php
use yii\bootstrap\Nav;
use yii\bootstrap\NavBar;
use app\helpers\App;
use yii\helpers\Html;

NavBar::begin([
'brandLabel' => 'My Company',
'brandUrl' => Yii::$app->homeUrl,
'options' => [
'class' => 'navbar-inverse navbar-fixed-top',
],
]);
echo Nav::widget([
'options' => ['class' => 'navbar-nav navbar-right'],
'items' => [
['label' => App::t('Home'), 'url' => ['/site/index']],
Yii::$app->user->isGuest ? (
['label' => App::t('Login'), 'url' => ['/site/login']]
) : (
'<li>'
. Html::beginForm(['/site/logout'], 'post')
. Html::submitButton(
App::t('Logout').' (' . Yii::$app->user->identity->username . ')',
['class' => 'btn btn-link logout']
)
. Html::endForm()
. '</li>'
),
],
]);
NavBar::end();
?>

I want to add functionality like these:
1. I want to leave else empty
example

Yii::$app->user->isGuest ? (
['label' => App::t('Sign up', 'app2'), 'url' => ['/site/registration']]
) : (
[]//want to leave empty
),

2. I want multiple array
example

Yii::$app->user->isGuest ? (
['label' => App::t('Sign up0', 'app2'), 'url' => ['/site/zczczcxz']],
['label' => App::t('Sign up1', 'app2'), 'url' => ['/site/qweqweqe']],
['label' => App::t('Sign up2', 'app2'), 'url' => ['/site/asdasd']]
) : (
['label' => App::t('Sign up4', 'app2'), 'url' => ['/site/oipoiopi']],
['label' => App::t('Sign up4', 'app2'), 'url' => ['/site/oipoiopi']]
),

Both example not working and throwing errors, I think there is one decision for both situation with errorsRead more