Posts Tagged with yii 2

Displaying 11-15 of 15 results.
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
Resolved: Yii PHP DateTime UNIX TimeStamp NOW
posted by admin on February 20, 2017

$date = new DateTime();
return $date->format('U');

Error:

Class 'namespace\DateTime' not found
Read more
Resolved: Yii2 Migration multiple insert
posted by admin on February 20, 2017
I want to insert multiple rows in migration

$this->insert //insert once

I want multipleRead more
Resolved: Yii2 Error Exception: Class 'Custom class' not found
posted by admin on February 15, 2017
I use in migration classes custom helper class Table, and in migration up process got an error like
Command:

./yii migrate

Result until error

Yii Migration Tool (based on Yii v2.0.11.2)

Total 2 new migrations to be applied:
m170213_124818_init
m170214_092410_domain

Apply the above migrations? (yes|no) [no]:yes
*** applying m170213_124818_init


Error Message:

Exception: Class 'yii\helpers\Table' not found (/var/www/html/basic/migrations/m170213_124818_init.php:10)


My class is in root directory in helpers directory

<?php
namespace yii\helpers;
class Table
{
public static $user = 'user';
public static $role = 'role';
public static $status = 'status';
public static $domain = 'domain';
}


In migration class

<?php
use yii\db\Migration;
use yii\helpers;

class m170213_124818_init extends Migration
{
public function safeUp()
{
/** User Create*/
$this->createTable('{{%'.helpers\Table::$user.'}}', [
'id' => $this->primaryKey(10)->notNull()->unsigned(),
. . .
], 'ENGINE=InnoDB');
}
}


How to resolve itRead more
Resolved: Yii2 slash 2f url problem
posted by admin on February 6, 2017
After installation Yii2, I try to navigate with pages of application, and in url I have problem with slashes

http://website.dev/index.php?r=site%2Fabout
http://website.dev/index.php?r=site%2Fcontact
http://website.dev/index.php?r=site%2Floginite%2Floginite%2Flogin

I want to slashes in url in place of %2FRead more