本文整理汇总了PHP中Accounts::hasAttribute方法的典型用法代码示例。如果您正苦于以下问题:PHP Accounts::hasAttribute方法的具体用法?PHP Accounts::hasAttribute怎么用?PHP Accounts::hasAttribute使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Accounts
的用法示例。
在下文中一共展示了Accounts::hasAttribute方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: actionCreate
public function actionCreate()
{
switch ($_GET['model']) {
// Get an instance of the respective model
case 'Contacts':
$model = new Contacts();
$this->modelClass = "Contacts";
$temp = $model->attributes;
break;
case 'Actions':
$model = new Actions();
$this->modelClass = "Actions";
$temp = $model->attributes;
break;
case 'Accounts':
$model = new Accounts();
$this->modelClass = "Accounts";
$temp = $model->attributes;
break;
default:
$this->_sendResponse(501, sprintf('Mode <b>create</b> is not implemented for model <b>%s</b>', $_GET['model']));
exit;
}
// Try to assign POST values to attributes
foreach ($_POST as $var => $value) {
// Does the model have this attribute? If not raise an error
if ($model->hasAttribute($var)) {
$model->{$var} = $value;
}
}
switch ($_GET['model']) {
// Get an instance of the respective model
case 'Contacts':
Yii::import("application.modules.contacts.controllers.DefaultController");
$controller = new DefaultController('DefaultController');
if ($controller->create($model, $temp, '1')) {
$this->_sendResponse(200, sprintf('Model <b>%s</b> was created with name <b>%s</b>', $_GET['model'], $model->firstName . " " . $model->lastName));
} else {
// Errors occurred
$msg = "<h1>Error</h1>";
$msg .= sprintf("Couldn't create model <b>%s</b>", $_GET['model']);
$msg .= "<ul>";
foreach ($model->errors as $attribute => $attr_errors) {
$msg .= "<li>Attribute: {$attribute}</li>";
$msg .= "<ul>";
foreach ($attr_errors as $attr_error) {
$msg .= "<li>{$attr_error}</li>";
}
$msg .= "</ul>";
}
$msg .= "</ul>";
$this->_sendResponse(500, $msg);
}
break;
case 'Accounts':
Yii::import("application.modules.accounts.controllers.DefaultController");
$controller = new DefaultController('DefaultController');
if ($controller->create($model, $temp, '1')) {
$this->_sendResponse(200, sprintf('Model <b>%s</b> was created with name <b>%s</b>', $_GET['model'], $model->name));
} else {
// Errors occurred
$msg = "<h1>Error</h1>";
$msg .= sprintf("Couldn't create model <b>%s</b>", $_GET['model']);
$msg .= "<ul>";
foreach ($model->errors as $attribute => $attr_errors) {
$msg .= "<li>Attribute: {$attribute}</li>";
$msg .= "<ul>";
foreach ($attr_errors as $attr_error) {
$msg .= "<li>{$attr_error}</li>";
}
$msg .= "</ul>";
}
$msg .= "</ul>";
$this->_sendResponse(500, $msg);
}
break;
case 'Actions':
Yii::import("application.modules.actions.controllers.DefaultController");
$controller = new DefaultController('DefaultController');
if ($controller->create($model, $temp, '1')) {
$this->_sendResponse(200, sprintf('Model <b>%s</b> was created with description <b>%s</b>', $_GET['model'], $model->actionDescription));
} else {
// Errors occurred
$msg = "<h1>Error</h1>";
$msg .= sprintf("Couldn't create model <b>%s</b>", $_GET['model']);
$msg .= "<ul>";
foreach ($model->errors as $attribute => $attr_errors) {
$msg .= "<li>Attribute: {$attribute}</li>";
$msg .= "<ul>";
foreach ($attr_errors as $attr_error) {
$msg .= "<li>{$attr_error}</li>";
}
$msg .= "</ul>";
}
$msg .= "</ul>";
$this->_sendResponse(500, $msg);
}
break;
default:
$this->_sendResponse(501, sprintf('Mode <b>create</b> is not implemented for model <b>%s</b>', $_GET['model']));
//.........这里部分代码省略.........