Roshan Book

My Tech Notebook

Category Archives: PHP

Starting YII development in ubuntu – Part 1

1. Download yii folder

2. Go to var/www directory in terminal

3. TO create a new project follow:

first you need to get into your webroot by

cd /var/www <– in my case

create a folder that you want your demo to be install in my case I create a folder named ‘blog’ under /var/www/yii/

then set permission to 777 by: sudo chmod 777

then type in the following command

php yii/framework/yiic.php webapp /var/www/yii/blog

if your php program has not been installed, the system will give you an install command then do it and come back to do the same.

then you can access your demo by http://localhost/yii/blog <— in my case

4. To enable gii

go to protected>config>main.php and uncomment gii module

5. To access gii generator go to http://localhost/myproj/demo/index.php?r=gii/default/login

6. To convert url mapping into path format go to config>main.php and uncomment

‘urlManager’=>array(
‘urlFormat’=>’path’,
‘rules’=>array(
‘<controller:\w+>/<id:\d+>’=>'<controller>/view’,
‘<controller:\w+>/<action:\w+>/<id:\d+>’=>'<controller>/<action>’,
‘<controller:\w+>/<action:\w+>’=>'<controller>/<action>’,
),
),

 

7. Passing variable data from controller to view

In Controller

public $message = ‘Hello World rom controller’;

public function actionIndex()
{
$this->render(‘index’,array(‘content’=>$this->message));
}

Now variable content is available to modified

In View

<?php echo $content ?>

Alternatively we could do

<?php echo $this->message   ?>

8. CRUD generation

a) Config database

b) Go to protected>>config>>main.php

c) Uncomment db componenent

d) Give the username , password, and db name

e) Comment out sqlite configuration which lie just above the mysql configuration

 

9. GO to gii

10. Select model generator

11. Enter table details and generate the model

12. We now have Message.php under model directory

13. Now click on CRUD generator

13. Enter Model name

14. Click generate

15. You can try it out by goign to baseurl/modelname

16. Access database content via these codes in controller

public $message = ”;

public function actionIndex()
{ $message=Message::model()->findByPK(3);
$this->message=$message->content;
$this->render(‘index’,array(‘content’=>$this->message));
}

Introduction to creating desktop applications with PHP and Titanium

Source: http://www.sanisoft.com/blog/2011/01/03/introduction-to-creating-desktop-applications-with-php-and-titanium/

Excerpts : 

What tools do you need ?

  • Download and install the Titanium DeveloperThe download and installation procedure has been discussed at length in the Titanium documentation in a simple and understandable way and even the steps on creating a new project and hence I am not putting the same here. I am assuming that you will download and comeback right here to know what next.
  • Text Editor with HTML / PHP syntax highlighting – If you are a web developer then you can’t be alive without one. Use your favorite.

On my Ubuntu 10.04 I got an error like : symbol lookup error: /usr/lib/lib-something: undefined symbol: something:

I did this to get rid of it :

– cd ~/.titanium/runtime/linux/1.0.0 if you install in your home dir.

or if you install in /opt/titanium/runtime/linux/1.0.0

– rm libgobject* libgthread* libglib* libgio*

Ready ?  What next ?

Follow http://www.sanisoft.com/blog/2011/01/03/introduction-to-creating-desktop-applications-with-php-and-titanium/ to read more

PHP Mysql notes

MYSQL

Index from : http://www.developphp.com/list_mysql.php

Connect to database script

$sqlCommand = “SELECT pagebody FROM pages WHERE id=’$pageid’ LIMIT 1”;
$query = mysqli_query($myConnection, $sqlCommand) or die (mysqli_error());
while ($row = mysqli_fetch_array($query)) {
$body = $row[“pagebody”];
}
mysqli_free_result($query);

 

Query the database 

 

PHP Crud

PHP CMS

PHP user authtication system

%d bloggers like this: