Thursday, January 23, 2014

YII framework tutorial for beginers

To create a YII base site
go to the folder where you want to create it
and run the following command
"YIIROOT_PATH\framework\yiic" webapp webAccessible
generates a site stub inside webAccessible folder
PS: YIIROOT_PATH\framework need not be web accessible

first login is
demo:demo
and
admin:admin

config files are in

protected\config folder of the stub
set DataBase details in protected/config/main.php
'db'=>array(
PS:comment default which is sqlite and uncomment the one below it for MYSQL
Gii tool
=======
edit protected\config\main.php
uncomment 3 lines pertaining to gii
set a password
edit 'ipFilters' carefully with the server name you use
http://www.yiiframework.com/doc/api/1.1/GiiModule#ipFilters-detail

or use localhost to use gii

http://localhost/YII_SITE_PATH/index.php?r=gii
pw:Crud password
CRUD files created by Gii will be array("protected".DS."controllers".DS."CRUD_NAMEController.php",
========= "protected".DS."models".DS."CRUD_NAME.php",
"protected".DS."views".DS."CRUD_NAME" /*this is folder*/);


Additionally the following files are created
protected\runtime\gii-1.1.14\CrudCode.php
protected\runtime\gii-1.1.14\ModelCode.php

Changing Field types(eg:text to drop down ) in CRUD forms
============================================
http://jmmurphy.blogspot.in/2013/05/using-yii-model-relations.html
http://stackoverflow.com/questions/17264317/need-help-to-create-crud-screen-with-dropdown-relation-using-yii-framework
Altering crud forms for multiple models in one go
======================================
http://www.yiiframework.com/wiki/384/creating-and-updating-model-and-its-related-models-in-one-form-inc-image/
this also contain example of transaction management $trans = Yii::app()->db->beginTransaction(); $trans->commit(); and $trans->rollback();

Module files created by GII will be in the folder
===================
protected\modules\MODULE_NAME\
they are created based on the templates in framework\gii\generators\module\templates\default.
additionally the file 'protected\runtime\gii-1.1.14\ModuleCode.php' is also created

Modules can be created without gii tool also though not necessary
http://www.linkedin.com/groups/how-create-modules-in-yii-1483367.S.156442090

Setting Module paramenters in protected/config/main.php
http://www.yiiframework.com/doc/guide/1.1/pt/basics.module

http://localhost/YII_SITE_PATH/index.php?r=greeting/index
or
http://YII_SITE/index.php/greeting/index
or even
=======
http://YII_SITE/greeting/index

after creating/editing .htaccess and protected/config/main.php

'urlFormat'=>'path',
'showScriptName'=>false,
//'caseSensitive'=>false, //NEVER SET THIS THIS WILL NOT LET MODULES LOAD

(should also enable mod_rewrite pache module for this to work)
as mentioned in
http://www.yiiframework.com/wiki/214/url-hide-index-php/

contollerId/ActionId
protected/controllers/GreetingController.php
protected/views/greeting/index.php



pass variable from controller to view by altering controller code from
=========================================================
$this->render('index);
to
$this->render('index',array('content' => $this->message));

and use $content variable in view file

you can use $this->message directly in view file as well

using database
--------------------------

http://vimeo.com/18448007

edit protected/config/main.php
comment
'db'=>array(
'connectionString' => 'sqlite:'.dirname(__FILE__).'/../data/testdrive.db',
),
uncomment the 'db' config of MYSQL below setting database details correctly

gii Model generator
=================
generates
models\Message.php where Message is the name of the model specified in 'Model generator' form

to use message from database
$message = Message::model()->findByPK(4);
$this->message = $message->content;
CRUD Generator
==================
use model name made with "Model Generator" and a suitable controller name

Make user login from db
==================
http://danaluther.blogspot.in/2010/03/yii-authentication-via-database.html (also mentions how to use CRDU in command line,check my addendum also )
http://www.yiiframework.com/doc/guide/1.1/en/topics.auth

Add additional admin users
============================
$auth=Yii::app()->authManager;
//if not already added run the following comment just once
//$role = $auth->createRole('admin', 'administrator');
$record=User::model()->findByAttributes(array('username'=>$username));//Check http://www.yiiframework.com/doc/api/1.1/CActiveRecord for all search functions available for User::model()
$userId = $record->id;
$auth->assign('admin',$userId);
Assigning Biz rule for role 'mcqadder' and checking in script
============================================
return in_array('mcqadder',array_keys(Yii::app()->authManager->getAuthAssignments(Yii::app()->user->id)));

Yii::app()->user->checkAccess('mcqadder')

Usefull functions to get parameter URL etc
=======================================
//Yii::app()->request->getQuery($key, $defaultValue) and getPost() with the same parameters.
//Yii::app()->controller->id and Yii::app()->controller->action->id
//ie(Yii::app()->request->url);
Create YII site url with params
=======================
Yii::app()->createUrl('faq/index', array('cid' => 'asas'))
Redirect
============
Yii::app()->request->redirect(Yii::app()->user->returnUrl);
Login and logut with code
===================
http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#login-and-logout
leave login for a certain period using Cookie
==================================
http://www.yiiframework.com/doc/guide/1.1/en/topics.auth#cookie-based-login

to change site name
==================
edit protected/config/main.php
change 'name' =>

to set title and meta dynamically
==============================
use the following code in ControllerAction
$this->pageTitle = 'New Title';

Yii::app()->clientScript->registerMetaTag('foo, bar', 'keywords');
Yii::app()->clientScript->registerMetaTag('foodescription, bardescription', 'description');
to set default meta values set them in protected/controllers/SiteController.php
Edit overall layout
===============
http://www.yiiframework.com/wiki/249/understanding-the-view-rendering-flow/
edit protected/views/layouts/main.php
Change Contact email
==================
'adminEmail' in protected/config/main.php
Change remove//Default Logins
==========================
http://stackoverflow.com/questions/10772615/yii-framework-remove-demo-admin-accounts
under protected/components you'll find UserIdentity.php, the users and their passwords will be declared in the authenticate function using an array.

To modify top menu
==================
edit protected\views\layouts\main.php
to ad external link or open in target_blank
array('label'=>'Gii', 'url'=>'http://SiteURL','linkOptions'=>array('target'=>'_blank')),

Useful Extensions
===============
GIIX to create CRUD forrelationsal tables
----------------------------------------------------------
http://www.yiiframework.com/extension/giix
https://github.com/rcoelho/giix
https://github.com/rcoelho/giix/blob/master/INSTALL

Running Queries
==============
http://sonsonz.wordpress.com/2011/05/05/executing-sql-statements/
Load Javascript
============
http://www.yiiframework.com/wiki/572/how-to-include-javascript-css/
Events and behaviors
===================
http://www.yiiframework.com/wiki/44/
Admin panel Basics
========================
http://www.yiiframework.com/wiki/33/
another method with yii behavior feature
http://www.yiiframework.com/wiki/63/organize-directories-for-applications-with-front-end-and-back-end-using-webapplicationend-behavior

Auth permissions
===================
http://www.yiiframework.com/doc/guide/1.1/en/topics.auth
http://www.benjaminlhaas.com/blog/installing-yii-users-and-rights-5-steps

Wednesday, June 20, 2012

Creating Firefox extension

Best editor notepad++

introduction
https://developer.mozilla.org/en/Building_an_Extension

http://www.slideshare.net/robnyman/how-to-write-your-first-firefox-extensio

new profile
https://developer.mozilla.org/en/Setting_up_extension_development_environment

"%ProgramFiles%\Mozilla Firefox\firefox.exe" -no-remote -P dev

profile folder:
http://kb.mozillazine.org/Profile_folder

%APPDATA%\Mozilla\Firefox\Profiles\[profile_id]\extensions

Monday, June 18, 2012

Excel Tips

www.excelforum.com/excel-programming/687263-saving-individual-tabs-as-files.html


http://www.ozgrid.com/forum/showthread.php?t=91553

http://stackoverflow.com/questions/9572342/macro-to-save-each-worksheet-into-separate-xls-files-with-visual-file-chooser

Steps to saves Excel tabs as CSV
-----------------------------------

1.Open Excel file
2.press ctrl f11
3.right click the diectory tree
4.select 'insert module'
5.copy and paste following code there
6.click run(play) button





' ---------------------- Directory Choosing Helper Functions -----------------------
' Excel and VBA do not provide any convenient directory chooser or file chooser
' dialogs, but these functions will provide a reference to a system DLL
' with the necessary capabilities
Private Type BROWSEINFO ' used by the function GetFolderName
    hOwner As Long
    pidlRoot As Long
    pszDisplayName As String
    lpszTitle As String
    ulFlags As Long
    lpfn As Long
    lParam As Long
    iImage As Long
End Type

Private Declare Function SHGetPathFromIDList Lib "shell32.dll" _
    Alias "SHGetPathFromIDListA" (ByVal pidl As Long, ByVal pszPath As String) As Long
Private Declare Function SHBrowseForFolder Lib "shell32.dll" _
    Alias "SHBrowseForFolderA" (lpBrowseInfo As BROWSEINFO) As Long

Function GetFolderName(Msg As String) As String
' returns the name of the folder selected by the user
Dim bInfo As BROWSEINFO, path As String, r As Long
Dim X As Long, pos As Integer
    bInfo.pidlRoot = 0& ' Root folder = Desktop
    If IsMissing(Msg) Then
        bInfo.lpszTitle = "Select a folder."
        ' the dialog title
    Else
        bInfo.lpszTitle = Msg ' the dialog title
    End If
    bInfo.ulFlags = &H1 ' Type of directory to return
    X = SHBrowseForFolder(bInfo) ' display the dialog
    ' Parse the result
    path = Space$(512)
    r = SHGetPathFromIDList(ByVal X, ByVal path)
    If r Then
        pos = InStr(path, Chr$(0))
        GetFolderName = Left(path, pos - 1)
    Else
        GetFolderName = ""
    End If
End Function
'---------------------- END Directory Chooser Helper Functions ----------------------

Public Sub DoTheExport()
Dim FName As Variant
Dim Sep As String
Dim wsSheet As Worksheet
Dim nFileNum As Integer
Dim xlsPath As String


xlsPath = GetFolderName("Choose the folder to export files to:")
If xlsPath = "" Then
    MsgBox ("You didn't choose an export directory. Nothing will be exported.")
    Exit Sub
End If
'MsgBox xlsPath

For Each wsSheet In Worksheets
        ' make a copy to create a new book with this sheet
        ' otherwise you will always only get the first sheet
        wsSheet.Copy
        ' this copy will now become active
        ActiveWorkbook.SaveAs Filename:=xlsPath + "\" + wsSheet.Name & ".CSV", FileFormat:=xlCSV, CreateBackup:=False
        ActiveWorkbook.Close

Next wsSheet

End Sub


 

Monday, August 8, 2011

Symfony framework

 download:http://www.symfony-project.org/installation
install:http://www.symfony-project.org/getting-started/1_4/en/

Porting
C:\wamp\bin\apache\Apache2.2.11\conf\httpd.conf
add

Listen 8082
uncomment
Include conf/extra/httpd-vhosts.conf


C:\wamp\bin\apache\Apache2.2.11\conf\extra\httpd-vhosts.conf
add
 # Be sure to only have this line once in your configuration
NameVirtualHost 127.0.0.1:8082

# This is the configuration for your project




DocumentRoot "C:\wamp\www\symfony_folder\web"
DirectoryIndex index.php

AllowOverride All
Allow from All




Edit
C:\wamp\www\symfony_folder\config\databases.yml



admin login is
host:8082/admin/login/login



main template is
C:\wamp\www\symfony_folder\apps\site_name\templates\layout.php
to checking  routing
check
C:\wamp\www\symfony_folder\apps\site_name\config\routing.yml

homepage:
  url:   /
  param: { module: top, action: index }

means check
C:\wamp\www\symfony_folder\apps\site_name\modules\top

there will be a indexSuccess.php file in templates folder



wordpress

Porting
  1. database config : wp-config.php
  2. SELECT * 
    FROM `wp_options` 
    WHERE option_name
    IN (
    'siteurl', 'home'
    );
  3. change site url in db:
    update wp_options` set `option_value` = 'wp_base_url' where option_name in('siteurl','home');
  4. if required,change RewriteBase in .htaccess

Wednesday, July 20, 2011

w3c

w3 validator
http://validator.w3.org/check?uri=

validate and entire site
http://www.htmlhelp.com/tools/validator/