framework/ directory of your PRADO installation. I am gonna demonstrate to you how to create Active Record classes for using in your application. Also, it can be used to test if your database configuring in the application.xml are correct or not.First and foremost, you need to create a directory inside your application where all these classes will reside. A general approach is creating all the Active Record classes in a single directory and then include the entire directory in your
application.xml to make them available to use in any page of your application. So, I have created a folder named App_Code/ inside my application directory. Check out the following image.
The table for which we will be creating the Active Record class is shown below. I have already created a sample table test with following structure in my database.mysql> desc test;You need to go to the shell prompt of your application now. Use the following command to do the same. I am executing this command from my document root directory. Refer to the image below for the directory structure.
+-----------+--------------+------+-----+---------+----------------+
| Field | Type | Null | Key | Default | Extra |
+-----------+--------------+------+-----+---------+----------------+
| id | int(10) | NO | PRI | NULL | auto_increment |
| test_text | varchar(100) | YES | | NULL | |
+-----------+--------------+------+-----+---------+----------------+
2 rows in set (0.24 sec)

$ php prado/framework/prado-cli.php shell sample_appYou will have the following interface when you have logged on.
www (I am here while executing the above command)
+
+------prado (main framework directory)
+ +
+ +---- framework
+ +
+ +------ prado-cli.php
+
+------sample_app
+
+--- prototected
+
+------ App_Code
Command line tools for Prado 3.1.7.Lets, generate our
** Loaded PRADO appplication in directory "sample_app\protected".
PHP-Shell - Version 0.3.1
(c) 2006, Jan Kneschke
>> use '?' to open the inline help
>>
ActiveRecord class for the test table. Execute the following command on the prado shell of your application. Make sure you have the App_Code/ folder in your application directory. The script does not create the folder. It already expects it to be there in which it creates the file.
>> generate test Application.App_Code.TestRecord
When the command has successfully executed, you will get the message as
>> generate test Application.App_Code.TestRecord
Writing class TestRecord to file C:\wamp\www\sample_app\protected\App_Code\TestRecord.php
This means your Active Record class is generated successfully and you can start using it in your application.
Happy PRADO till next time ... ;-)
No comments:
Post a Comment