本文整理汇总了PHP中Web::callHook方法的典型用法代码示例。如果您正苦于以下问题:PHP Web::callHook方法的具体用法?PHP Web::callHook怎么用?PHP Web::callHook使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Web
的用法示例。
在下文中一共展示了Web::callHook方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: index_ALL
/**
* @hook example_add_row_action(array(<ExampleData> 'data', <String> 'actions')
* @param Web $w
*/
function index_ALL(Web $w)
{
// adding data to the template context
$w->ctx("message", "Example Data List");
// get the list of data objects
$listdata = $w->Example->getAllData();
// prepare table data
$t[] = array("Title", "Data", "Actions");
// table header
if (!empty($listdata)) {
foreach ($listdata as $d) {
$row = array();
$row[] = $d->title;
$row[] = $d->data;
// prepare action buttons for each row
$actions = array();
if ($d->canEdit($w->Auth->user())) {
$actions[] = Html::box("/example/edit/" . $d->id, "Edit", true);
}
if ($d->canDelete($w->Auth->user())) {
$actions[] = Html::b("/example/delete/" . $d->id, "Delete", "Really delete?");
}
// allow any other module to add actions here
$actions = $w->callHook("example", "add_row_action", array("data" => $d, "actions" => $actions));
$row[] = implode(" ", $actions);
$t[] = $row;
}
}
// create the html table and put into template context
$w->ctx("table", Html::table($t, "table", "tablesorter", true));
}
示例2: useredit_POST
/**
* Handle User Edit form submission
*
* @param <type> $w
*/
function useredit_POST(Web &$w)
{
$w->pathMatch("id");
$errors = $w->validate(array(array("login", ".+", "Login is mandatory")));
if ($_REQUEST['password'] && $_REQUEST['password'] != $_REQUEST['password2']) {
$error[] = "Passwords don't match";
}
$user = $w->Auth->getObject("User", $w->ctx('id'));
if (!$user) {
$errors[] = "User does not exist";
}
if (sizeof($errors) != 0) {
$w->error(implode("<br/>\n", $errors), "/admin/useredit/" . $w->ctx("id"));
}
$user->login = $_REQUEST['login'];
$user->fill($_REQUEST);
if ($_REQUEST['password']) {
$user->setPassword($_REQUEST['password']);
} else {
$user->password = null;
}
$user->is_admin = isset($_REQUEST['is_admin']) ? 1 : 0;
$user->is_active = isset($_REQUEST['is_active']) ? 1 : 0;
$user->update();
$contact = $user->getContact();
if ($contact) {
$contact->fill($_REQUEST);
$contact->private_to_user_id = null;
$contact->update();
}
$w->callHook("admin", "account_changed", $user);
$w->msg("User " . $user->login . " updated.", "/admin/users");
}
示例3: useradd_POST
/**
* Handle User Edit form submission
*
* @param <type> $w
*/
function useradd_POST(Web &$w)
{
$errors = $w->validate(array(array("login", ".+", "Login is mandatory"), array("password", ".+", "Password is mandatory"), array("password2", ".+", "Password2 is mandatory")));
if ($_REQUEST['password2'] != $_REQUEST['password']) {
$errors[] = "Passwords don't match";
}
if (sizeof($errors) != 0) {
$w->error(implode("<br/>\n", $errors), "/admin/useradd");
}
// first saving basic contact info
$contact = new Contact($w);
$contact->fill($_REQUEST);
$contact->dt_created = time();
$contact->private_to_user_id = null;
$contact->insert();
// now saving the user
$user = new User($w);
$user->login = $_REQUEST['login'];
$user->setPassword($_REQUEST['password']);
$user->is_active = !empty($_REQUEST['is_active']) ? $_REQUEST['is_active'] : 0;
$user->is_admin = !empty($_REQUEST['is_admin']) ? $_REQUEST['is_admin'] : 0;
$user->is_group = 0;
$user->dt_created = time();
$user->contact_id = $contact->id;
$user->insert();
$w->ctx("user", $user);
// now saving the roles
$roles = $w->Auth->getAllRoles();
foreach ($roles as $r) {
if (!empty($_REQUEST["check_" . $r])) {
if ($_REQUEST["check_" . $r] == 1) {
$user->addRole($r);
}
}
}
$w->callHook("admin", "account_changed", $user);
$w->msg("User " . $user->login . " added", "/admin/users");
}