UrlsでCRUD
revision 2577
Urlsを使った一番単純なCRUDの作り方。
デフォのtemplateを使うので、それぞれURL直打ち
project.xml
<project rhacover="1.4.1" version="1.0.0" name="sample" xmlns="http://rhaco.org" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://rhaco.org http://media.rhaco.org/project.xsd"> <database name="sample"> <table name="products" class="product" admin="true"> <column name="id" /> <column name="name" /> </table> </database> </project>
index.php
<?php
include("__init__.php");
Rhaco::import("generic.Urls");
Rhaco::import("model.Product");
$redirect = Rhaco::url("index.php/read");
$object = new Product();
$parser = Urls::parser(array(
"^create"=>array("method"=>"create","args"=>array($object,$redirect)),
"^read"=>array("method"=>"read","args"=>$object),
"^update/([\d]+)"=>array("method"=>"update","args"=>array($object,$redirect)),
"^delete/([\d]+)"=>array("method"=>"drop","args"=>array($object,$redirect)),
"^detail/([\d]+)"=>array("method"=>"detail","args"=>$object),
));
$parser->write();
?>
Create: 〜/index.php/create
Read: 〜/index.php/read
Update: 〜/index.php/update/1
Delete: 〜/index.php/delete/1
2008/02/01 02:56:06
アプリパス/resources/templates/generic/テーブル名_form.html を置いておくと読んでくれますね!便利!