Monday, December 31, 2012

FuelPHP 3. Using Auth Package

Auth


1. Config


    Add auth to always_load array

        return array(

            'default_timezone'   => 'Asia/Seoul',

            'always_load'  => array(
                    'packages'  => array(
                     'orm',
                     'auth',
                  ),
            ),
        );

2. DB Table Name

    Notice the table name should be 'users' by looking at the file J:/fuel/packages/auth/config/simpleauth.php


/**
     * DB table name for the user table
     */
'table_name' => 'users',

3. Create DB Table by using oil

        php oil g model user username:string password:string group:int email:string last_login:string login_hash:string profile_fields:string

    Those fields are as shown in the simpleauth.php

    And then perform migration

        php oil r migrate


4. Create a controller

    php oil g controller users login logout register




Sunday, December 30, 2012

FuelPHP 2. Start after Installation

Start

I followd this tutorial http://ucf.github.com/fuelphp-crash-course/

1. Create a database


    uncomment the orm package in the app/config/config.php




return array(

'default_timezone'   => 'Asia/Seoul',

'always_load'  => array(
'packages'  => array(
'orm',
),
),
);



    create a database with any name, say fuel_dev

        mysql> create database fuel_dev;

    update the app/config/development/db.php

        return array(
            'default' => array(
                'connection'  => array(
                    'dsn'        => 'mysql:host=localhost;dbname=fuel_dev',
                    'username'   => 'xyz',
                    'password'   => '12345',
                ),
            ),
        );

2. Scaffolding

    Use oil to generate a scaffolding which fills the database with a table and creates some fuel runnable codes

        J:/vhosts/words> php oil generate scaffold messages name:string message:text

    Here, string is varchar(255)
    Some fields are automatically added
    Those added fields are id(int, 11, auto_increment), created_at(int, 11), and updated_at(int, 11)

    It does not create a real table in the database, but just a schema as a file

3. Migration


    To create a real database table, do migration

        J:/vhosts/words> php oil refine migrate

    That will create a real table named messages
    And another table is created named migration


FuelPHP 1. Installation

Installation

1. Download

    http://fuelphp.com

    version 1.4 (as of 1st January 2013)

2. Environment of Apache

    My document_root of Apache is actually J:/www
    But the virutal localhost is J:/vhosts which is configured in httpd-vhosts.conf


    <Directory j:/vhosts>
Order Deny,Allow
Allow from all
    </Directory>

    <VirtualHost *:80>
        DocumentRoot "j:/vhosts"
        ServerName localhost
    </VirtualHost>

    <VirtualHost *:80>
        DocumentRoot "j:/vhosts/words"
        ServerName words
    </VirtualHost>

3. Installation

    I've made 2 directories, one in the document_root (J:/vhosts) and the other in outside the document_root (J:/) and moved the files there

    1. public files: J:/vhosts/words/(assets, htaccess, index.php)

        (Move oil to this directory)


    2. fuel files: J:/fuel/(app, core, packages, htaccess, LICENSE)


4. Edit firephp/index.php

    This index.php is actually found in public/index.php from the downloaded archive
    But now in J:/vhosts/words/index.php

    The links to the installed programs are modified

    /**
     * Path to the application directory.
     */
    define('APPPATH', realpath(__DIR__.'/../../fuel/app/').DIRECTORY_SEPARATOR);

    /**
     * Path to the default packages directory.
     */
    define('PKGPATH', realpath(__DIR__.'/../../fuel/packages/').DIRECTORY_SEPARATOR);

    /**
     * The path to the framework core.
     */
    define('COREPATH', realpath(__DIR__.'/../../fuel/core/').DIRECTORY_SEPARATOR);


    * modify oil the same as index.php

    visit http://localhost/words to see the installed welcome page


5. Set TimeZone


    Modify app/config/config.php


return array( 'default_timezone' => 'Asia/Seoul', );


    Test the timezone by touching J:/fuel/app/views/welcome/index.php

    <h1>Welcome!</h1>
    <?php echo date("Y-m-d H:i:s"); ?>

    visit http://localhost/words to see the localized date time


6. Visit HOME

    http://localhost/words/

    This will visit the fuelphp located under the document_root
    And is routed to the fuelphp application pages as indicated by the words/index.php

    The chain of links to the welcome page is as follows

    http://localhost/words/
    ==> J:/vhosts/words/index.php
    ==> J:/fuel/app/bootstrap.php
    ==> J:/fuel/app/classes/controller/welcome.php
    ==> action_index() in controller/welcome.php
    ==> J:/fuel/app/views/welcome/index.php

    if you add hello to the above url, you will see another demo page

    http://localhost/words/hello

    which calls one method called function action_hello() in welcome.php

7. Change the Default Page


    It is possible to change the route of the first page which is automatically directed when the url has nothing but the base_url like http://www.world.com/

    Edit the config file named routes.php in app/config


    return array(
    '_root_'  => 'main/index',  // The default route
    '_404_'   => 'main/404',    // The main 404 route

    'hello(/:name)?' => array('main/hello', 'name' => 'hello'),
    );

 

8. Test oil

    To execute php, add the path to php.exe to the environment variable in the computer system

        c:\wamp\bin\php\php5.3.5;

    Then go to the oil directory (now in J:/vhosts/words), and run windows cmd utility

    And run oil as

        J:\vhosts\words> php oil








Saturday, December 29, 2012

Apache Virtual Host


Virtual Host


There are two files that need to be touched


  1. First edit those files, and then rerun the services of apache and mysqld and others if necessary
  2. And visit http://localhost/[virtual host name]  ex. http://localhost/words


1. windows/system32/drivers/etc/hosts/

127.0.0.1       localhost
127.0.0.1 books
127.0.0.1 code
127.0.0.1 joy
127.0.0.1 orange
127.0.0.1 test
127.0.0.1 words


2. apache/conf/extra/

<VirtualHost *:80>

    DocumentRoot "j:/vhosts"
    ServerName localhost
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "j:/vhosts/www/books"
    ServerName books
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "j:/vhosts/codeigniter"
    ServerName code
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "j:/vhosts/dreamweaver"
    ServerName dw
</VirtualHost>

<VirtualHost *:80>
    ServerAdmin arbago@gmail.com
    DocumentRoot "j:/vhosts/www/orange"
    ServerName orange
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "j:/vhosts/test"
    ServerName test
</VirtualHost>

<VirtualHost *:80>
    DocumentRoot "j:/vhosts/words"
    ServerName words
</VirtualHost>