Posts Tagged with class

Displaying 1-8 of 8 results.
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

./yii migrate

Result until error

Yii Migration Tool (based on Yii v2.0.11.2)

Total 2 new migrations to be applied:

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

namespace yii\helpers;
class Table
public static $user = 'user';
public static $role = 'role';
public static $status = 'status';
public static $domain = 'domain';

In migration class

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 Helper folder, helper namespace, helper class
posted by admin on February 14, 2017
In yii1 I created helpers folder in public and move all my helper classes and autoload them from main.php setting file

// autoloading model and component classes

I have three questions

  1. Where create helpers classes folder
  2. How to create helpers classes
  3. How to autoload or use helpers classes
Read more
Wiki: Yii 1.1: CGridView. Add custom class to table rows preserving original odd and evenwiki
posted by admin on November 3, 2016
Lets say we have such a CGridView widget showing a list of users for administrator. Users have status „active“ or „disabled“. Grid widget puts class „odd“ or „even“ to rows and we want to preserve this. So we want to add a class „disabled“ to rows with disabled users.

$this->widget('zii.widgets.grid.CGridView', array(
'rowCssClassExpression' => '
( $row%2 ? $this->rowCssClass[1] : $this->rowCssClass[0] ) .
( $data->status ? null : " disabled" )
'name' => 'status',
'value' => '$data->status0->title',
'header' => Yii::t( 'app', 'Tools' ),

$model here is a User model pushed to view from controller. $data->status0->title here is User's property from relation to other model (why it is $data and not $model see bellow).
All „magic“ we do in „rowCssClassExpression“ property. Its value is a PHP expression. Expression is evaluated for every data row. Result of evaluation is used as the CSS class name. Note, that PHP expression is string.
We put „rowCssClassExpression“ property to „top“ CGridView properties – thus class will be aplied to row. If we put another „cssClassExpression“ property to some column – we can set a class for single cell. E.g.:

'name' => 'status',
'value' => '$data->status0->title',
'cssClassExpression' => '"foo" . (2+3) ."bar"',

as result we will have

<td class="foo5bar">

(note the difference between „rowCssClassExpression“ and „cssClassExpression“) From widget you can access such a variables:
  • $row : the row number (zero-based)
  • $data : the data model for the row
  • $this : the column object. As you can see we use all of them.


( $row%2 ? $this->rowCssClass[1] : $this->rowCssClass[0] ) .

evaluates to 0,1,0,1... as rows are processed and original „odd“ or „even“ values are returned. CGridView::rowCssClass property is array containing default class values (in means of html element attribute). This property is ignored in widget because of rowCssClassExpression property is used. But values are accessible :) This expressions then is concatenated (note dot at the end) with:

( $data->status ? null : " disabled" )

$data here is User model and „status“ is its property (0 or 1 in this case). You can't access $model variable from those string expressions.Read more
Wiki: Bootstrap CSS Style colors classeswiki
posted by admin on October 12, 2016
Add meaning through text-colors with the classes below. Links will darken on hover:
Class Description

.text-muted Text styled with class "text-muted"
.text-primary Text styled with class "text-primary"
.text-success Text styled with class "text-success"
.text-info Text styled with class "text-info"
.text-warning Text styled with class "text-warning"
.text-danger Text styled with class "text-danger"

Add meaning through background-colors with the classes below. Links will darken on hover just like text classes:
Class Description

.bg-primary Table cell is styled with class "bg-primary"
.bg-success Table cell is styled with class "bg-success"
.bg-info Table cell is styled with class "bg-info"
.bg-warning Table cell is styled with class "bg-warning"
.bg-danger Table cell is styled with class "bg-danger"
Read more
Resolved: PHP compose class property by string and value
posted by admin on May 22, 2016
I have object or class.

class Class1{
public $language = "English";
public $languageru = "Russian";

public function composeValue(){
//return my value, or empty or "ru"

$class = new Class1();
$value = $class->composeValue();
// I want something like this
echo $class->language.$value
//But it is not working
Read more
Wiki: Yii 1.1: Add id or class to CMenu itemswiki
posted by admin on April 12, 2016
CMenu comes with a lot of great customization options built in. One of the most used is the class 'active' being added to menu item. But, what if you want to add your own class or id to a menu item ?

It's very easy, you just need to use the 'itemOptions'.

If you want a menu like :

<ul id="myMenu">
<li id="first"><a href="#"><span>First</span></a></li>
<li id="second"><a href="#"><span>Second</span></a></li>

Just do :

<?php $this->widget('application.components.MyMenu', array(
'id' => 'myMenu',
'items' => array(
array('label' => 'First', 'url' => array('#'), 'itemOptions'=>array('id' => 'first'), ),
array('label' => 'First', 'url' => array('#'), 'itemOptions'=>array('id' => 'second'), ),
Read more
Wiki: Post content classification for blogs, vlogs, apps, games
posted by admin on April 7, 2016
altUsing our rating system, you can communicate familiar and locally relevant content ratings to your users and help improve app engagement by targeting the right audience for your content.

How ratings are used
  • Inform consumers about the age appropriateness of your app.
  • Block or filter your content in certain territories or to specific users where legally required.
  • Evaluate your app’s eligibility for special developer programs.

Rating authorities & descriptions

Content is generally suitable for all ages. May contain minimal cartoon, fantasy or mild violence and/or infrequent use of mild language.

Content is generally suitable for ages 10 and up. May contain more cartoon, fantasy or mild violence, mild language and/or minimal suggestive themes.

Content is generally suitable for ages 13 and up. May contain violence, suggestive themes, crude humor, minimal blood, simulated gambling and/or infrequent use of strong language.

Content is generally suitable for ages 17 and up. May contain intense violence, blood and gore, sexual content and/or strong language.

Content suitable only for adults ages 18 and up. May include prolonged scenes of intense violence, graphic sexual content and/or gambling with real currency.Read more
Resolved: Wordpress post_class add class
posted by admin on March 22, 2016
How to add class in post_class() function.


<div id="post-<?php the_ID(); ?>" <?php post_class(); ?>>

HTML output

<div id="post-4564" class="post post-4564 category-48 category-dancing logged-in">
Read more