我有几页需要登录,所以链接到这些页面的所有控制器都以
$this->checkSession();
//...rest of the code
Run Code Online (Sandbox Code Playgroud)
CheckSession应验证会话是否仍然有效,否则显示消息并停止执行控制器中的其余代码:
function checkSession()
{
if (!$this->session->userdata('is_logged_in'))
{
//the session has expired!
$data['main'] = 'confirmation_message';
$data['title'] = "Session expired";
$this->load->vars($data);
$this->load->view('template');
exit();
}
}
Run Code Online (Sandbox Code Playgroud)
.我期待这些指令按顺序发生,但我只得到一个空白页面.如何确保只在加载所有视图后才执行exit()?
我正在使用引导程序,并且CSS具有响应性,因此它可以在较小的设备上很好地缩小.但是,当视口较小时(例如,在移动设备上),我希望按钮也缩小.
<button name="button" type="submit" id="edit_button-46" class="btn btn-default" value="edit" >Edit</button>
Run Code Online (Sandbox Code Playgroud)
基本上在较小的设备上,应将btn-xs类添加到所有按钮中.
我可以通过Jquery完成这个,但是想知道bootstrap是否已经具有此功能?
我有一些数据,我必须显示为表格.
我想我应该从控制器传递数据为$ data ['events'] = array(.....
然后加载视图以显示它们.
<?php
$this->load->library('table');
echo $this->table->generate($events);
?>
Run Code Online (Sandbox Code Playgroud)
这不起作用 - 它给出致命错误:在非对象上调用成员函数generate()
如果我在控制器中粘贴相同的代码,显然使用 - > generate($ data ['events']表会正确显示.
我应该得到的视图无法加载库,或者我做错了什么?或者我应该在控制器中捕获库的输出并将其发送到视图?
我有一个表格,下面列出了场地和提交按钮.他们应该在同一条线上,但由于场地列表是动态的,它可能会变得太长并按下按钮.
我在考虑为select设置max-width属性,但我不清楚这是否适用于所有浏览器.您对解决方法有什么建议吗?
<form action="http://localhost/ci-llmg/index.php/welcome/searchVenueForm" method="post" class="searchform">
<select name="venue">
<option value="0" selected="selected">Select venue...</option>
<option value="1">venue 0</option>
<option value="2">club 1</option>
<option value="3">disco 2</option>
<option value="4">future test venue</option>
</select>
<input type="submit" name="" value="Show venue!" class="submitButton" />
</form>
Run Code Online (Sandbox Code Playgroud)
CSS:
.searchform select {
max-width: 320px;
}
.searchform input.submitButton {
float: right;
}
Run Code Online (Sandbox Code Playgroud) 我正在尝试使用codeigniter发送电子邮件,并希望该消息跨越多行.
$address = $this->input->post('email');
$subject = 'Please complete your registration';
$message = 'Thanks for registering! \n To complete your registration, please click on (or copy and paste in your browser) the following link: ' . base_url(). "users/confirmRegistration/" . $confirmation_code; //note the '\n' after thanks for registering
$this->load->library('email');
$this->email->from('me@mysite.com', 'myname');
$this->email->to($address);
$this->email->subject($subject);
$this->email->message($message);
$this->email->send();
Run Code Online (Sandbox Code Playgroud)
我希望邮件在"感谢注册"之后以换行符到达,但我得到了
感谢您的注册!ñ完成注册(等等......)
我试过\ r \n但结果几乎相同:
感谢您的注册!要完成(等等).这就像应用了striplash功能..
有任何想法吗?
我正在使用bootstrap构建一个表单.我有一个输入字段,我希望用户插入日期.HTML以这种方式编码:
<div class="form-group">
<label for="entry_date">Date of entry:</label>
<input type="date" name='entry_date' class="form-control" id="entry_date"
<span class="help-block">Some helpful words here</span>
</div>
Run Code Online (Sandbox Code Playgroud)
Bootstrap使用占位符自动填充此字段dd/mm/yyyy.我怎么能覆盖这个呢?我需要它,所以我可以重新填充该字段(例如,在部分提交后重新加载表单时)
我收到此错误"致命错误:当我尝试使用我的某个模型时,调用未定义的方法CI_DB_mysql_driver :: findVenueInfo()".
我有这个锚的视图:
echo anchor('welcome/searchVenue/' . $row->venue_id, $row->venue);
Run Code Online (Sandbox Code Playgroud)
它生成如下链接:http://localhost/ci-llmg/index.php/welcome/searchVenue/1
调用的方法是
function searchVenue()
{
$this->load->model('venues');
//get venue info
$data['info'] = $this->venues->findVenueInfo($this->uri->segment(3)); //this line generates the error
}
Run Code Online (Sandbox Code Playgroud)
并且模型中的findVenueInfo函数(venues.php)是:
function findVenueInfo($id)
{
$data = array();
$this->db->where('id', $id);
$Q = $this->db->get('venues');
if ($Q->num_rows() > 0)
{
foreach ($Q->result() as $row)
{
$data[] = $row;
}
}
$Q->free_result();
return $data;
}
Run Code Online (Sandbox Code Playgroud)
..但结果是致命错误:调用未定义的方法CI_DB_mysql_driver :: findVenueInfo()我可能错过了一些愚蠢的东西,但无法让它工作!你怎么看?
我有一个包含一些共享相关数据的字典:
share_data = {'2016-06-13':{'open': 2190, 'close':2200}, '2015-09-10':{'open': 2870, 'close':2450} # and so on, circa 1,500 entries
Run Code Online (Sandbox Code Playgroud)
有没有一种按顺序迭代字典的方法,所以最先检索最早的日期,然后很快检索一个?
谢谢!
这里是新手。有人可以向我解释为什么在这段代码的末尾打印“none”,但仅在函数内部调用时才打印吗?
背景:我有一个变量(share_data),其中包含一些列表:
share_data =
[['Date', 'Ticker', 'Company', 'Mkt Cap', 'VM Rank', 'Value Rank', 'Momentum Rank'],
['2016-08-27', 'BEZ', 'Beazley', '2,063', '89', '72', '76'],
['2016-08-30', 'BEZ', 'Beazley', '2,063', '89', '72', '76'],
['2016-08-31', 'BEZ', 'Beazley', '2,050', '89', '72', '75'],
['2016-09-01', 'BEZ', 'Beazley', '2,039', '96', '73', '93'],
['2016-09-02', 'BEZ', 'Beazley', '2,069', '90', '72', '77'],
['2016-09-03', 'BEZ', 'Beazley', '2,120', '96', '70', '94'],
['2016-09-06', 'BEZ', 'Beazley', '2,106', '90', '71', '77'],
['2016-09-07', 'BEZ', 'Beazley', '2,085', '89', '71', '76'],
['2016-09-08', 'BEZ', 'Beazley', '2,091', '89', '72', '77'],
['2016-09-09', 'BEZ', …Run Code Online (Sandbox Code Playgroud) 我需要从两个表中检索数据.第一个是事件列表,第二个是场地列表.
我在两个表中都有一个具有相同名称的字段:events.venue(这是一个ID)和venues.venue是该地方的名称,比如说"blues bar".这些表可以在events.venue = venues.id上加入.
我模特的片段:
$this->db->select('events.*, venues.*');
$this->db->join('venues', 'events.venue = venues.id');
if ($date != 'all')
{
$this->db->where('date', $date);
}
if ($keyword)
{
$this->db->like('description', $keyword);
$this->db->or_like('band', $keyword);
$this->db->or_like('venue', $keyword);
$this->db->or_like('genre', $keyword);
}
$Q = $this->db->get('events');
if ($Q->num_rows() > 0)
{
foreach ($Q->result() as $row)
{
$data[] = $row;
}
}
$Q->free_result();
return $data;
Run Code Online (Sandbox Code Playgroud)
视图片段:
foreach ($events as $row) {
echo "<p>{$row->band} ({$row->genre})<br />";
echo "Playing at: {$row->venue}<br /></p>"; // echoes "blues bar"
//more here...
}
Run Code Online (Sandbox Code Playgroud)
2个问题:1)为什么$ row->场地回应场地.而不是events.venue?
B)我如何区分它们?例如.如果我想同时回应events.venue和venues.venue怎么办?我可以做一些像"SELECT venues.venue as …
我刚刚发布了我的网站,使用codeigniter创建.
整个目录都在我的公共文件夹中,包括配置文件(在public/system/application/config中).
我只想仔细检查:我是否必须将此文件移动到另一个非公共目录?我认为codeigniter不允许任何直接访问,但我不是100%肯定..
谢谢,P
如果任何变量与某些字符串匹配,我有一段代码需要运行。代码看起来很长而且不是很pythonic:
if candidate_job_title in ('ERROR', 'NOT AVAILABLE') or candidate_company in ('ERROR', 'NOT AVAILABLE') or candidate_location in ('ERROR', 'NOT AVAILABLE'):
# do something
Run Code Online (Sandbox Code Playgroud)
我能想到的最好的就是这个,我还能做些什么来使它更具可读性?
if any (v in ('ERROR', 'NOT AVAILABLE') for v in (candidate_job_title, candidate_company, candidate_location):
# do something
Run Code Online (Sandbox Code Playgroud)