我再次被困,需要你的帮助。我有时无法在我的网页上加载CSS。实际上,昨天它工作正常,但今天它没有加载。所以,我删除了整个文件夹并上传了另一个我在localhost上使用的文件夹。然后它再次正常工作。重新启动浏览器后,我面临问题。
以下是我的代码的详细信息:
控制器:Users.php
:
<?php
session_start();
class Users extends CI_Controller
{
public function viewinsert1()
{
$this->load->view('createfinal');
}
public function viewinsert2()
{
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'trim|required|valid_email|xss_clean');
$this->load->view('personalfinal');
}
public function viewinsert3()
{
$this->load->view('socialfinal');
}
public function viewupdate()
{
$this->load->view('view_update');
}
public function viewdelete()
{
$this->load->view('view_delete');
}
public function show()
{
// $this->load->model('user_model');
$data['results'] = $this->user_model->get_users();
$this->load->view('user_view', $data);
// foreach ($result as $object)
// {
// echo $object->id . "</br>";
// }
}
// public function insert()
// {
// $username = "Peter";
// $password = "12345";
// $this->user_model->create_users([
// 'username' => $username,
// 'password' => $password
// ]);
// }
public function insert()
{
// echo $this->input->post('password') . "</br>";
// echo $_POST['username'];
//echo $email = $this->input->post('email');
//echo $_SESSION["email"];
// $email = $this->input->post('email');
// $_SESSION["email"] = $email;
// $_SESSION["pass"] = $pass;
// $_SESSION["cpass"] = $cpass;
// $_SESSION["fname"] = $fname;
// $_SESSION["lname"] = $lname;
// $_SESSION["phone"] = $phone;
// $_SESSION["address"] = $address;
$this->load->library('form_validation');
$this->form_validation->set_rules('email', 'email', 'trim|required|valid_email|xss_clean');
$this->form_validation->set_rules('fname', 'firstname', 'trim|alpha|required|xss_clean');
$this->form_validation->set_rules('lname', 'lastname', 'trim|alpha|required|xss_clean');
$this->form_validation->set_rules('phone', 'phone', 'trim|numeric|required|integer|exact_length[10]');
$this->form_validation->set_rules('address', 'address', 'trim|alpha_dash|required');
$this->form_validation->set_rules('pass', 'cpass', 'trim|required|matches[cpass]|md5');
$this->form_validation->set_rules('pass', 'cpass', 'trim|required');
if ($this->form_validation->run() == FALSE)
{
$this->load->view('createfinal');
echo "Error";
}
else
{
$data = array(
'email' => $_SESSION["email"],
'firstname' => $_SESSION["fname"],
'lastname' => $_SESSION["lname"],
'phone' => $_SESSION["phone"],
'address' => $_SESSION["address"],
'twitter' => $this->input->post('twitter'),
'facebook' => $this->input->post('facebook'),
'googleplus' => $this->input->post('gplus'),
'password' => $_SESSION["pass"],
'confirm' => $_SESSION["cpass"],
);
// echo var_dump($data);
$result = $this->user_model->create_users($data);
$this->load->view('createfinal');
echo "<h1>The data has been inserted</h1>";
}
}
public function update()
{
if (isset($_POST['update']))
{
$id = $this->input->post('id');
$data = array(
'username' => $this->input->post('username'),
'password' => $this->input->post('password')
);
$this->user_model->update_users($data, $id);
echo "<h1> Data is updated successfully:) </h1>";
$this->load->view('view_update');
}
else
{
echo "Oops! There is something wrong!";
}
}
public function delete()
{
if (isset($_POST['delete']))
{
$id = $this->input->post('id');
$this->user_model->delete_users($id);
echo "<h1>The data has been deleted.</h1>";
}
else
{
echo "<h3>No Such data exist!</h3>";
}
}
}
?>
这是我想加载的视图..
createfinal.php
:
<!DOCTYPE html>
<html>
<head>
<title>Login Form</title>
<link rel="stylesheet" type="text/css" href="<?php echo base_url();?>css/style.css">
</head>
<body>
<!-- multistep form -->
<form id="msform" action="viewinsert2" method="post">
<!-- progressbar -->
<ul id="progressbar">
<li class="active">Account Setup</li>
<li>Social Profiles</li>
<li>Personal Details</li>
</ul>
<!-- fieldsets -->
<fieldset>
<h2 class="fs-title">Create your account</h2>
<h3 class="fs-subtitle">This is step 1</h3>
<input type="text" name="email" placeholder="Email" />
<input type="password" name="pass" placeholder="Password" />
<input type="password" name="cpass" placeholder="Confirm Password" />
<input type="submit" name="next" class="next action-button" value="Next" />
</fieldset>
</body>
</html>
css文件夹与应用程序文件夹并行。
答案 0 :(得分:2)
您是否正确设置了基本网址?这是在config.php
$config['base_url'] = 'http://' . $_SERVER['SERVER_NAME'] . '/';
另外你怎么装这个?您可以在autoload.php
$autoload['helper'] = array('url');
或者您在方法中调用它:
$this->load->helper('url');
如果我是你,我会使用base_url
或var_dump(base_url)
调试print_r(base_url)
的内容,以查看正在制作的内容;
答案 1 :(得分:1)
函数base_url()
应返回基本路径(不带index.php)
您可以通过添加反斜杠来修复它:
<link rel="stylesheet" type="text/css" href="<? echo base_url();?>/css/style.css">
或从配置中删除index.php:
$config['base_url'] = 'siteurl/ci/';
另一种方式是
在constants.php
(在config目录中)中定义一个常量
define("LAYOUT_URL","http://localhost/yoursite/css/");
&#34; CSS&#34;这里的文件夹我假设是在应用程序文件夹中。现在您可以在页面中附加css,如
<link rel="stylesheet" type="text/css" href="<?php echo LAYOUT_URL;?>style.css">
答案 2 :(得分:0)
我已经解决了这个错误。 问题是关于基本网址。在第一个我已经设置基本网址如下:
$_config['base_url'] = 'http://127.0.0.1/crudfinal';
如此。它实际上是在我的电脑中找到css文件。所以,我把它改成了这个:
$_config['base_url'] = 'http:// . $_SERVER['HTTP_HOST'] . /crudfinal';
最后它正常工作。但它也适用于 $ _ SERVER [&#39; SERVER_NAME&#39;]。
我还从网址中删除了index.php。
谢谢你们的帮助:)