本文整理汇总了PHP中arr::unshift方法的典型用法代码示例。如果您正苦于以下问题:PHP arr::unshift方法的具体用法?PHP arr::unshift怎么用?PHP arr::unshift使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类arr
的用法示例。
在下文中一共展示了arr::unshift方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: action_index
public function action_index()
{
$this->template->content = View::factory('admin/projects/create')->bind('post', $post)->bind('errors', $errors)->bind('associates', $assoc);
$assoc = DB::query(Database::SELECT, 'SELECT id, name FROM associates ORDER BY name')->execute()->as_array('id', 'name');
// Add an option for "no associate"
arr::unshift($assoc, 0, '- none -');
$post = Validate::factory($_POST)->filter(TRUE, 'trim')->rule('title', 'not_empty')->rule('title', 'regex', array('/^[\\pL\\pP\\s]{4,255}$/iu'))->rule('associate_id', 'not_empty')->rule('associate_id', 'in_array', array(array_keys($assoc)))->rule('completed', 'not_empty')->rule('completed', 'date')->rule('website', 'regex', array('#^https?://.+$#'));
if ($post->check($errors)) {
if (empty($post['associate_id'])) {
// Make the associate NULL
$post['associate_id'] = NULL;
// Use only the title for the slug
$post['slug'] = url::title($post['title']);
} else {
// Use the title with associate for the slug
$post['slug'] = url::title($post['title']) . '/with/' . url::title($assoc[$post['associate_id']]);
}
if (empty($post['website'])) {
// Make the website value NULL
$post['website'] = NULL;
}
// Get the values of the array
$values = $post->as_array();
// Convert the completed date into a timestamp
$values['completed'] = strtotime($values['completed']);
$query = DB::query(Database::INSERT, 'INSERT INTO projects (title, associate_id, completed, website, slug) VALUES (:values)')->bind(':values', $values)->execute();
// Set a cookie message
cookie::set('message', 'Created new project with an ID of ' . $query);
// Redirect back to the same page
$this->request->redirect(url::site($this->request->uri));
}
}