Mostrar mensagens com a etiqueta akelos. Mostrar todas as mensagens
Mostrar mensagens com a etiqueta akelos. Mostrar todas as mensagens

quinta-feira, 7 de agosto de 2008

Akelos PHP Framework How to create an application

In the last post I told you how to install Akelos, if you had a problem just post a comment and we'll try to help you.

Now I will try to explain what happened when you installed that "booklink" application previously.

Go to database and see what it looks like:
mysql -u root -p booklink_dev
and do
show tables;
desc books;


Now, check the file app/installers/book_installer.php (inside the booklink dir).
This is where the default data entity is defined. Akelos created it for you. This is used to create the database table that stores the books.
Change it to:

function up_1(){
$this->createTable('books',
'id,'. // the key
'title,'. // the title of the book
'description,'. // a description of the book
'author_id,'. // the author id. This is how Akelos will know how to link
'published_on' // the publication date
);
$this->createTable('authors',
'id,'. // the key
'name' // the name of the author
);
}
function down_1(){
$this->dropTables('books','authors');
}

Please note that there are naming conventions for the column names (for instance if the column name is id, then it's the primary key, and if suffix is _at then it's a datetime, etc.) To full control all your tables, check http://phplens.com/lens/adodb/docs-datadict.htm (I didn't by now)

Now, to update our application with this new model, we need to migrate (execute it from booklink directory):

php script/migrate book install


Now you can go to the database
mysql -u root -p booklink_dev
and do
show tables;
desc books;
desc authors;

Now we need to create the scaffold for both entities: books and authors.
To do so, we will execute:
php script/generate scaffold book
and
php script/generate scaffold author


If you get this error:
There where collisions when attempting to generate the scaffold.
Please add force=true to the argument list in order to overwrite existing files.

Then do:
php script/generate scaffold book --force
and
php script/generate scaffold author --force

(the --force will akelos to rewrite some files)

Now check your application. Cool isn't it?

Installing Akelos on Windows

Install Akelos on Windows with a example.

I'm assuming that there's an Apache 2 installed and a PHP 5 in the machine.

First download akelos framework
http://www.akelos.org/download

Then extract it, for example, to
c:\akelos_framework
then execute go to c:\akelos_framework and execute
php script/setup -d c:\httpdocs\booklink

(I'm assuming that c:\httpdocs is your Apache DocumentRoot)

Now create the database:
mysql -u root -p
Enter password: ******
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.0.41-community-nt MySQL Community Edition (GPL)

Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

mysql> CREATE DATABASE booklink;
Query OK, 1 row affected (0.00 sec)

mysql> CREATE DATABASE booklink_dev;
Query OK, 1 row affected (0.02 sec)

mysql> CREATE DATABASE booklink_tests;
Query OK, 1 row affected (0.01 sec)

mysql> GRANT ALL ON booklink.* TO cassio@localhost IDENTIFIED BY "pass";
Query OK, 0 rows affected (0.09 sec)

mysql>
mysql> GRANT ALL ON booklink_dev.* TO cassio@localhost IDENTIFIED BY "pass";
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> GRANT ALL ON booklink_tests.* TO cassio@localhost IDENTIFIED BY "pass";
Query OK, 0 rows affected (0.00 sec)

mysql>
mysql> FLUSH PRIVILEGES;
Query OK, 0 rows affected (0.00 sec)

mysql> exit;
Bye

Open in the browser:
http://127.0.0.1/booklink/public/

should display :


Welcome aboard
You’re using The Akelos Framework!
Getting started

1.
Configure your environment

Run a step by step wizard for creating a configuration file or read README.txt instead.

Start the configuration wizard


Configure your database according to the DB you've created previously.

Configure your language (in my case for example: pt,pt_PT)

Then go to command line, to the c:\httpdocs\booklink directory and run

php script/generate scaffold Book

which will tell you that some files where created.

Now... magic: just go to http://127.0.0.1/booklink/book and start playing with your application!!!

I will be posting the next round in a short time: how to create your own application