有时无法加载 css
Can not load css sometimes
我再次陷入困境,需要您的帮助。有时我无法在我的网页上加载 css。实际上,昨天它工作正常,但今天没有加载。所以,我删除了整个文件夹并上传了另一个我在本地主机上使用的文件夹。然后它再次工作正常一段时间。重新启动浏览器后,我遇到了问题。
以下是我的代码的详细信息:
控制器: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文件夹与应用程序文件夹平行。
函数 base_url()
应该 return 基本路径(没有 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/");
"css" 文件夹我假设在应用程序文件夹内。现在您可以在
之类的页面中附加 css
<link rel="stylesheet" type="text/css" href="<?php echo LAYOUT_URL;?>style.css">
你的基地 url 设置正确吗?这是在 config.php
中设置的
$config['base_url'] = 'http://' . $_SERVER['SERVER_NAME'] . '/';
还有你是如何加载这个的?您可以在 autoload.php
中自动加载
$autoload['helper'] = array('url');
或者您在方法中调用它:
$this->load->helper('url');
如果我是你,我会使用 var_dump(base_url)
或 print_r(base_url)
来调试 base_url
的内容,以查看生成的内容;
我已经解决了错误。
问题出在基数 url 上。首先,我将基数 url 设置如下:
$_config['base_url'] = 'http://127.0.0.1/crudfinal';
所以。它实际上是在我的计算机中找到 css 文件。所以,我把它改成这样:
$_config['base_url'] = 'http:// . $_SERVER['HTTP_HOST'] . /crudfinal';
终于可以正常工作了。但它也适用于 $_SERVER['SERVER_NAME'].
我还从 url 中删除了 index.php。
谢谢大家的帮助:)
我再次陷入困境,需要您的帮助。有时我无法在我的网页上加载 css。实际上,昨天它工作正常,但今天没有加载。所以,我删除了整个文件夹并上传了另一个我在本地主机上使用的文件夹。然后它再次工作正常一段时间。重新启动浏览器后,我遇到了问题。
以下是我的代码的详细信息:
控制器: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文件夹与应用程序文件夹平行。
函数 base_url()
应该 return 基本路径(没有 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/");
"css" 文件夹我假设在应用程序文件夹内。现在您可以在
之类的页面中附加 css<link rel="stylesheet" type="text/css" href="<?php echo LAYOUT_URL;?>style.css">
你的基地 url 设置正确吗?这是在 config.php
$config['base_url'] = 'http://' . $_SERVER['SERVER_NAME'] . '/';
还有你是如何加载这个的?您可以在 autoload.php
$autoload['helper'] = array('url');
或者您在方法中调用它:
$this->load->helper('url');
如果我是你,我会使用 var_dump(base_url)
或 print_r(base_url)
来调试 base_url
的内容,以查看生成的内容;
我已经解决了错误。 问题出在基数 url 上。首先,我将基数 url 设置如下:
$_config['base_url'] = 'http://127.0.0.1/crudfinal';
所以。它实际上是在我的计算机中找到 css 文件。所以,我把它改成这样:
$_config['base_url'] = 'http:// . $_SERVER['HTTP_HOST'] . /crudfinal';
终于可以正常工作了。但它也适用于 $_SERVER['SERVER_NAME'].
我还从 url 中删除了 index.php。
谢谢大家的帮助:)