Showing posts with label Yii Tips/Help. Show all posts
Showing posts with label Yii Tips/Help. Show all posts

Friday, 31 March 2017

Image upoad with dir creation in YII

if(!is_dir(Yii::getPathOfAlias('webroot').'/'.$imagepath))
{
          if(!defined('FS_CHMOD_DIR')){
            define('FS_CHMOD_DIR', 0755);
           }
        mkdir(Yii::getPathOfAlias('webroot').'/'.$imagepath);
}

$OriImage = Yii::getPathOfAlias('webroot').'/'.$model->{$field}; 
$stat = stat(dirname($OriImage));
$perms = $stat['mode'] & 0000666;
$logo->saveAs($OriImage);
@chmod($OriImage,$perms);

Friday, 30 January 2015

Thursday, 28 August 2014

Add Drop Down to Yii Grid


Add  Drop Down to Yii Grid

$myColumns [] = array(
    'type' => 'raw',
    'header' => "Page Size",
'filter' => CHtml::dropDownList('pageSize', $pageSize, Yii::app()->params['defaultPageDdSize'], array('style' => 'font-size:11px; width: 50px; padding: 0px 0px 0px 0px; height: initial; ',)),
      'value' => '"<a href=\'javascript:void(0);\' onclick=\'renderView(".$data->id_games.")\' class=\'view\' data-toggle=\'tooltip\' title=\'\' data-original-title=\'View\'>
                  <i class=\'icon-eye-open\'></i></a> &nbsp;
      <a href=\'' . Yii::app()->controller->createUrl('update&id=$data->id_games') . '\' class=\'update\'  data-toggle=\'tooltip\' title=\'\' data-original-title=\'Update\'>
        <i class=\'icon-pencil\'></i></a> &nbsp;
<a class=\'delete\' onclick=\'renderDeleteForm(".$data->id_games.")\' data-toggle=\'tooltip\' title=\'\' data-original-title=\'Delete\'>
        <i class=\'icon-trash\'></i></a>
"',
    'htmlOptions' => array('class' => 'button-column','style' => 'width:62px')
);

Monday, 18 August 2014

Get the count of records from a table in yii


Get the count of records from a table .
The best of way of retrieving the count of a query in yii.

For all record
$sql = "SELECT COUNT(*) FROM tablename;
$numRecordsFound = Yii::app()->db->createCommand($sql)->queryScalar();

For Criteria Based record.

$sql = "SELECT COUNT(*) FROM tablename where columnName=".$columnValue;
$numRecordsFound = Yii::app()->db->createCommand($sql)->queryScalar();

Friday, 25 July 2014

How to create Yii Web application and new info about Yii Framework

About Yii
Yii is a high-performance PHP framework best for developing Web 2.0 applications.
Yii helps Web developers build complex applications and deliver them on-time.
Yii is pronounced as Yee or [ji:], and is an acroynym for "Yes It Is!".
Yii 1.1 is the latest stable version.
The latest version of Yii 2 is 2.0.0 beta, released on April 13, 2014.
Yii 2.0 is not ready for production use yet. It is currently under heavy development.

How to set up yii web application in localhost.

1. Down load the latest yii framework (yii version1.1) from below link
   http://www.yiiframework.com/download/

2. Extract the code from zip or gaiz file,
you will get following folders,
demos
framework,
requirements
and following four files
CHNAGELOG
LICENSE
README
UPGRADE

3. Put all files to the root level in you localhost.
for the xampp user they can place these files under the htdocs folder.

4. run the below code for create the yii app (project)
Create Yii Project In Local Host With Xampp Using Command Line
Step 1 open command line
Step 2 run below command it will create all the default structure for the project.
Here "newyiiprojectname"  is the name of the folder(project) you want to create. you can change it as per your choice.
C:\xampp\php>php C:/xampp/htdocs/framework/yiic.php webapp C:\xampp\htdocs\newyiiprojectname
once you run above command it will ask you to create a web application under the defined path with yes/no option.
here if you type yes and press enter it will create the new yii app(project) with the given folder name.

Now your application is ready. You can access it by using following link
http://localhost/newyiiprojectname/


How to setup yii project in localhost

Create Yii Project In Local Host With Xampp Using Command Line

Step1 open command line

Step 2 run below command it will create all the default structure for the project.

here "newyiiprojectname"  is the name of the folder(project) you want to create. you can change it as per your choice.
C:\xampp\php>php C:/xampp/htdocs/framework/yiic.php webapp C:\xampp\htdocs\newyiiprojectname

Friday, 18 July 2014

How to hide index.php from url in yii

URL rewriting in Yii to hide index.php

To hide the index.php from url you have to make the changes in config/main.php  as shown below,
‘urlManager’=>array(
                              ‘urlFormat’=>’path’,
                              ‘showScriptName’=>false, //this option will be hide the index.php from url
                              ‘rules’=>array(
                                                ‘<controller:\w+>/<id:\d+>’=>’<controller>/view’,
                                               ‘<controller:\w+>/<action:\w+>/<id:\d+>’=>’<controller>/<action>’,
                                              ‘<controller:\w+>/<action:\w+>’=>’<controller>/<action>’,
                                             ),
), 
and create new .htaccess file in the same directory as my index.php file shown as below,
RewriteEngine  On
RewriteBase  /
RewriteCond   %{REQUEST_FILENAME} !-f
RewriteCond   %{REQUEST_FILENAME} !-d
RewriteRule    ^(.*)\?*$ index.php/$1 [L,QSA]
You can change the ”RewriteBase /’  as per project location like if project is located in ‘abc/′ of webroot.
then it change like as    RewriteBase  /abc

That will make sure your auto-generated links (CHtml::link or zii.widgets.CMenu) do not have index.php in them. This will not work without the .htaccess file. The reason is that the .htaccess file rewrites the url to point to index.php/$1 so that Yii actually gets the request properly. You will not see the index.php in the url at any time though.

Tuesday, 11 March 2014

How to Check Url Access In YII for Role based Access

Below function return true and false(1 or null) either yii user is able to access the url(authItemName) or not.

Explample.
Player list
$url = http://localhost/YiiProject/index.php?r=player/playerList/index
$allowedAccess = $this->checkUrlAccess($url );
if($allowedAccess){
 echo "You are allowed to access Url";
}else{
 echo 'Access denied';
}
function checkUrlAccess($authItemName)
  {
     #New Code ADDED            
            $allowedAccess='';
        if (strpos($authItemName, '?r=') != false)
        {
                   
            $urlQueryString=explode('?r=',$authItemName);          
            if (strpos($urlQueryString[1], '/') != false)
            {
                $parts = explode('/', $urlQueryString[1]);
                if ($this->upperCaseFirstLetter)
                {
                  foreach ($parts as $i => $part)
                  {
                    $parts[$i] = ucfirst($part);
                  }
                }
                $moduleName=$controllerName=$actionName='';
                $numOfParts = count($parts);
                if ($numOfParts > 2)
                {
                  $moduleName=$parts[$numOfParts - 3];
                }
                                $controllerName=$parts[$numOfParts - 2];
                $actionName=$parts[$numOfParts - 1];
                                $itemName = '';                   
                                 if(!empty($moduleName)){
                                         $itemName .= $moduleName . '.';
                                 }
                                 $itemName .= $controllerName;
                 $user = Yii::app()->getUser();
                 if ($user->isGuest){
                           if(empty($moduleName)){
                               $allowedAccess =   Yii::app()->beforeControllerAction($controllerName,$actionName);
                                             }
                 }else{
                      if ($user->checkAccess($itemName . '.*')){
                         $allowedAccess = 1;
                      }else{
                          $itemName .= '.' . $actionName;
                          if ($user->checkAccess($itemName, array())){
                              $allowedAccess = 1;
                          }
                      }
                                            if(empty($moduleName) && empty($allowedAccess)){
                                                $allowedAccess =   Yii::app()->beforeControllerAction($controllerName,$actionName);
                                             }
                 }
          
             }
        }
        #END
                return $allowedAccess;
   
  }

List OF BANK PAN Numbers

List OF BANK PAN Numbers Bank/Home Loan Providers PAN Number Allahabad Bank AACCA8464F Andhra Bank AABCA7375C Axis Bank...