Latest news:

New android application Islamic Video has been released. its a free islamic video application for android smartphone. Download now!

Yii2 - Get Current Action ID in main.php


In a layout you can access the current controller via $this->context, and so the current action id by $this->context->action->id

For reference

Views: 2850

SyntaxError: expected expression, got '<'

Assumption here is that you're referencing the script incorrectly and the web server is serving a 404 html page. Make sure the js file is where you're referencing it from.

for reference

Views: 4104

jQuery Set Content - text(), html(), and val()

We will use the same three methods from the previous page to set content:

  • text() - Sets or returns the text content of selected elements
  • html() - Sets or returns the content of selected elements (including HTML markup)
  • val() - Sets or returns the value of form fields

The following example demonstrates how to set content with the jQuery text(), html(), and val() methods:


    $("#test1").text("Hello world!");
    $("#test2").html("<b>Hello world!</b>");
    $("#test3").val("Dolly Duck");

Views: 1795

Yii2 pagination

Pagination represents information relevant to pagination of data items.

When data needs to be rendered in multiple pages, Pagination can be used to represent information such as total item count, page size, current page, etc. These information can be passed to pagers to render pagination buttons or links.

The following example shows how to create a pagination object and feed it to a pager.

Controller action:

public function actionSearch($q = '') {
        $this->layout = 'site_main';

        $q = trim($q);

        $sql = "SELECT * FROM
(select p.product_id as 'sid',p.name_en,p.name_ar,p.description_en,description_ar,p.image, 'product' as 'type', 'none' as 'category_type'
from tbl_products p
select sl.service_location_id as 'sid' ,sl.name_en,sl.name_ar,sl.description_en,sl.description_ar,sl.image,'servicelocation' as 'type' ,'none' as 'category_type'
from tbl_service_locations sl
as search
WHERE search.name_en LIKE '$q%' or search.name_ar LIKE '$q%' or search.description_en LIKE '$q%' or search.description_ar LIKE '$q%'  
        $query = Yii::$app->db->createCommand($sql)->queryAll();

        $count = sizeof($query);

        //echo $count;

        $dataProvider = new SqlDataProvider([
            'sql' => $sql,
            'totalCount' => $count,
            'pagination' => [
                'pageSize' => 10,

        //$models = $dataProvider->query;

        return $this->render('search', [
                    'q' => $q,
                    'result' => $dataProvider->getModels(),
                    'dataProvider' => $dataProvider,
                    'count' => $count,

View :

foreach ($result as $row) {

 // display $model here


// display pagination

echo yiiwidgetsLinkPager::widget([
    'pagination' => $dataProvider->pagination,

For reference please visit



Views: 3737

How to create virtual column using MySQL SELECT?

something like

    SELECT id, email, IF(actived = 1, 'enabled', 'disabled') AS account_status
FROM users

this allow you to make operations and show it as columns.


you can also use joins and show operaitons as columns:

    SELECT,, IF( IS NULL, 'no selected', as country
FROM users u LEFT JOIN countries c ON u.country_id =

See the

for refference

Views: 1592

Yii2 leftJoin()


$query = new Query;
$query    ->select(['tbl_user.username AS name', 'tbl_category.type as Category'])  
        ->leftJoin('tbl_category', 'tbl_category.createdby = tbl_user.userid')
$command = $query->createCommand();
$data = $command->queryAll();

Views: 1865

Yii2 innerJoinWith()


$model = User::find()
    ->innerJoinWith('comments', false)
// equivalent to the above
$model = User::find()
    ->joinWith('comments', false, 'INNER JOIN')


$query = new Query;
$query    ->select(['SELECT COLUMNS'])  
        ->join(    'JOIN_TYPE',
$command = $query->createCommand();
$data = $command->queryAll();               

Sample 1:

$query = new Query;
$query    ->select([
        'tbl_user.username AS name',
        'tbl_category.categoryname as  Category',
    ->join('LEFT OUTER JOIN', 'tbl_category',
                'tbl_category.createdby =tbl_user.userid')        
    ->join('LEFT OUTER JOIN', 'tbl_document',
                'tbl_category.cid =tbl_document.did')
    ->LIMIT(5)    ;
$command = $query->createCommand();
$data = $command->queryAll();   

Views: 2087

Yii2 joinWith()


Sample 1:

$model = User::find()

Sample 2:

$model = User::find()

Views: 2022

Yii2 Relation Model

Relation Model

$model = User::find()
    foreach ($model as $user) {
        // get data from relation model
        $comments = $user->comments;
        foreach($comments as $comment){

Views: 1237

Yii2 GridView sorting and pagination using pajax

use yiiwidgetsPjax;

Add above line in the beginning of your view. 

<?php Pjax::begin(); ?>

<?= GridView::widget([
    'dataProvider' => $dataProvider,
    'filterModel' => $searchModel,
    'columns' => [
        ['class' => 'yiigridSerialColumn'],


            'class' => 'yiigridActionColumn',
            'template' => '{view}',
]); ?>

<?php Pjax::end(); ?>


Views: 1591

Oracle reset system password

Use the following. we can change the oracle system password.

SQL> connect / as sysdba

SQL> alter user <username> identified by <password>;


Views: 820

Yii2 Turning on Pretty URLs

First, let's enable Yii2's pretty URLs with mod_rewrite. On the Yii home page, if you click on the About menu option, the URL will be something like http://localhost/hello/web/index.php?r=site%2Fabout. We'd like to change that to http://localhost/hello/web/site/about.

The config subdirectory includes environment configurations for your web and console applications as well as the future database settings. Edit /config/web.php to add urlManagement to the current web application. Add the following urlManager section within the components array:

Then, create an .htaccess file within /web where the primary index.php file exists:

Make sure mod_rewrite is running locally on MAMP; if not, check out this Stack Overflow guide.

In your browser, visit this URL: http://localhost/hello/web/site/about. You should see the Yii application About page and clicking on other menu options should bring up pretty URLs.

Views: 1124

Subscribe Us

Follow Us