我想要实现的是一个简单的登录页面,如果用户登录成功,则重定向到主页面,否则保持登录页面.
我有1个名为的控制器login,和1个名为的模型main.当用户单击登录按钮时,将调用login/login_send.
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Login extends CI_Controller{
function __construct() {
parent::__construct();
$this->load->model('model_login');
}
function index()
{
if ($this->model_login->is_logged_in())
{
redirect('main');
}
else
{
// load login page
$data['main'] = 'view_login';
$data['style'] = 'style_login';
$this->load->view('template', $data);
}
}
function login_send()
{
$this->form_validation->set_rules('username', 'Username', 'trim|required');
$this->form_validation->set_rules('password', 'Password', 'trim|required');
if ($this->form_validation->run() == FALSE)
{
$this->index();
}
else
{
if ( $this->model_login->validate_user() )
{
$user_session_data = array(
'username' => $this->input->post('username'),
'is_logged_in' …Run Code Online (Sandbox Code Playgroud) 我在 iOS 14 中型小部件中显示 3 行,如下所示:
row 1
-------
row 2
-------
row 3
-------
Run Code Online (Sandbox Code Playgroud)
我的视图结构在这里:
VStack {
ForEach(records, id: \.id) { item in
ZStack {
// some views
}
.widgetURL(URL(string: "wig://\(item.id)"))
}
Divider()
}
Run Code Online (Sandbox Code Playgroud)
似乎第一项和第二项的小部件 URL被第三项覆盖,所有深层链接都将打开第三项的内容。
为 ForEach 生成的视图添加深层链接的正确方法是什么?
我试图在drupal中实现hook_menu.
function menufun_menu() {
$items['menufun'] = array(
'title' => 'Menu Fun',
'title callback' => 'menufun_title',
'page callback' => 'menufun_greeting',
'file' => 'menufun_greeting.inc',
'page arguments' => array('aaa', 'bbb', 'ccc', 'ddd'),
'access callback' => 'user_access',
'access arguments' => array('receive greeting'),
'type' => MENU_NORMAL_ITEM,
'weight' => -1,
);
$items['menufun/farewell'] = array(
'title' => 'Farewell',
'page callback' => 'menufun_farewell',
'file' => 'menufun_greeting.inc',
'access callback' => 'user_access',
'access agruments' => array('receive greeting'),
'type' => MENU_NORMAL_ITEM,
);
return $items;
}
Run Code Online (Sandbox Code Playgroud)
但是,上面的代码会出现这两个错误:
Notice: Undefined offset: 0 in …Run Code Online (Sandbox Code Playgroud) 我下载CodeIgniter 2.1.0,然后按照CodeIgniter 2.1.0上的教程进行操作.
问题是当我尝试在此URL中提交表单时:
http://localhost/CodeIgniter/index.php/news/create
Run Code Online (Sandbox Code Playgroud)
该页面将重定向到此URL:
http://localhost/CodeIgniter/index.php/news/localhost/CodeIgniter/index.php/news/create
Run Code Online (Sandbox Code Playgroud)
我厌倦了很多改变route.php的方法,但它不起作用.我怎样才能解决这个问题??
route.php
$route['news/create'] = 'news/create';
$route['news/(:any)'] = 'news/view/$1';
$route['news'] = 'news';
$route['(:any)'] = 'pages/view/$1';
$route['default_controller'] = 'pages/view';
Run Code Online (Sandbox Code Playgroud)
这是表单页面的代码:
public function create()
{
$this->load->helper('form');
$this->load->library('form_validation');
$data['title'] = 'Create a news item';
$this->form_validation->set_rules('title', 'Title', 'required');
$this->form_validation->set_rules('text', 'text', 'required');
if ($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('news/create');
$this->load->view('templates/footer');
}
else
{
$this->news_model->set_news();
$this->load->view('news/success');
}
}
Run Code Online (Sandbox Code Playgroud)
我注意到当页面加载时的表单页面,下面的代码段将被执行,但是,else段从未得到执行的更改.
if ($this->form_validation->run() === FALSE)
{
$this->load->view('templates/header', $data);
$this->load->view('news/create');
$this->load->view('templates/footer');
}
Run Code Online (Sandbox Code Playgroud)
这是表单页面,没什么特别的,只需调用上面显示的create函数即可. create.php
<h2>Create a news item</h2>
<?php echo …Run Code Online (Sandbox Code Playgroud)