在我的codeigniter控制器函数中,我使用以下代码生成我的视图并插入所有必要的内容:
$left_column = $this->load->view('widgets/sub_navigation', $subnav_data, true);
$left_column .= $this->load->view('widgets/search_box', '', true); //Set data to be loaded into columns
$left_column_base = $this->load->view('widgets/assist_navigation', '', true);
$center_column = 'this is center column';
$right_column = $this->load->view('widgets/ask_us_a_question', '', true);
$right_column .= $this->load->view('widgets/newsletter', '', true);
$right_column .= $this->load->view('widgets/latest_news', '', true);
$this->template->inject_partial('left_column', $left_column); //Inject data into the partial columns
$this->template->inject_partial('left_column_base', $left_column_base);
$this->template->inject_partial('center_column', $center_column);
$this->template->inject_partial('right_column', $right_column);
$this->template->build('template',$data);
Run Code Online (Sandbox Code Playgroud)
我使用的是三列布局,上面的代码指示了每个列中显示的内容.它以非常模块化的方式工作,允许我快速自定义每个页面.
有没有办法简化上面的代码,使用数组可能,减少重复代码,使事情更干?
我正在使用jQuery的getJSON函数从我的控制器页面返回一个JsonResult.
这是网页中的jQuery代码:
$.getJSON("/Test/GetJsonWFA", null, function (data) {
$(data).each(function () {
alert("call succeeded");
//alert(data);
});
Run Code Online (Sandbox Code Playgroud)
这是控制器代码:
public JsonResult GetJsonWFA() {
List<WorkFlowAssignment> listWFAs = new List<WorkFlowAssignment>();
listWFAs.Add(new WorkFlowAssignment() { ID = 1, WorkFlowName = "WorkFlowName1" });
listWFAs.Add(new WorkFlowAssignment() { ID = 2, WorkFlowName = "WorkFlowName2" });
return Json(listWFAs, JsonRequestBehavior.AllowGet);
}
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:500内部服务器错误.
如果我更换WorkFlowAssignment在GetJsonWFA用一个简单的类一切正常.
它似乎与列表中的对象类型有关.
该WorkFlowAssignment类有许多属性和方法.
谁能指出我正确的方向?
我正在我的网站上创建一个下拉菜单,除了一件事之外,或多或少成功地完成了任务.
当悬停在下拉菜单上时,主菜单链接的悬停状态会因为我不再悬停在其上而消失.
如何在悬停在下拉项目上时保持链接上的活动状态样式?
我已将代码复制到http://cssdesk.com/PZBM2,如果您将鼠标悬停在第一个列表项上,您将看到我正在谈论的悬停状态和下拉列表.
这是代码:
/*Main nav*/
.main_nav_container{
margin-top:10px;
margin-bottom:10px;
display:block;
float:right;
}
ul.main_nav{
margin:0;
padding:0;
}
ul.main_nav li{
display:inline-block;
margin:0;
padding:0;
}
ul.main_nav li a{
font-size:13px;
display:block;
font-weight:bold;
position:relative;
height:25px;
line-height:25px;
padding:0 13px;
text-decoration:none;
color:#1122cc;
border:1px solid transparent;
}
ul.main_nav li a:hover{
text-decoration:underline !important;
border-top:solid 1px #ccc;
border-left:solid 1px #ccc;
border-right:solid 1px #ccc;
}
ul.main_nav li ul{
display:none;
position:absolute;
background: #fff;
margin:0;
padding:0;
border:solid 1px #ccc;
-moz-border-radius: 4px;
-webkit-border-radius: 4px;
-khtml-border-radius: 4px;
border-radius: 4px;
}
ul.main_nav li …Run Code Online (Sandbox Code Playgroud) 我正在使用codeigniters表单助手为我的网站设置反馈表单.
我的表单已创建并验证已实施,所有工作.
我唯一的问题是添加set_value()函数以在发生错误时重新填充表单.
我无法让它在我的无线电输入上工作,如何将set_value()函数添加到无线电类型.
码:
<ul>
<li><?php echo form_radio('found_by', 'newspaper_advert', set_value('found_by')); ?> Newspaper advert</li>
<li><?php echo form_radio('found_by', 'press_release', set_value('found_by')); ?> Press release</li>
<li><?php echo form_radio('found_by', 'text_message', set_value('found_by')); ?> Text message</li>
<li><?php echo form_radio('found_by', 'email', set_value('found_by')); ?> Email</li>
<li><?php echo form_radio('found_by', 'refferal', set_value('found_by')); ?> Referred to by a friend</li>
<li><?php echo form_radio('found_by', 'telemarketing', set_value('found_by')); ?> Telemarketing</li>
<li><?php echo form_radio('found_by', 'leaflet_flyer', set_value('found_by')); ?> Leaflet or flyer</li>
<li><?php echo form_radio('found_by', 'radio', set_value('found_by')); ?> Radio</li>
<li><?php echo form_radio('found_by', 'television', set_value('found_by')); ?> Television</li>
<li><?php echo …Run Code Online (Sandbox Code Playgroud) 如何在codeigniter中的下拉列表中使用set_select()(表单助手的一部分):
它用于记住用户选择的选项.
$guide_options = array('investments' => 'Investments',
'wills' => 'Wills',
'tax-planning' => 'Tax planning',
'life-insurance' => 'Life insurance',
'currency-exchange' => 'Currency exchange',
'retirement-planning' => 'Retirement planning',
'international-healthcare' => 'International healthcare',
'savings-plans' => 'Savings plans',
'education-planning' => 'Education planning',
'sipps' => 'SIPPS',
'qrops' => 'QROPS',
'qnups' => 'QNUPS',
'mortgages' => 'Mortgages',
'other' => 'Other service'
);
echo form_dropdown('guide', $guide_options, 'investments');
Run Code Online (Sandbox Code Playgroud)
表格帮助指南:http://codeigniter.com/user_guide/helpers/form_helper.html
我试图为我的控制器创建一个构造函数,该构造函数引用一个我自动加载的帮助程序中包含的函数.
该功能检查用户是否已登录,如果是,则将其重定向到登录页面.
看来我没有正确设置构造,因为我收到以下错误:
Fatal error: Call to undefined method Profile::is_logged_in()
Run Code Online (Sandbox Code Playgroud)
这是控制器:
<?php
if (!defined('BASEPATH'))
exit('No direct script access allowed');
class Profile extends CI_Controller {
public function __construct()
{
parent::__construct();
//function inside autoloaded helper, check if user is logged in, if not redirects to login page
$this->is_logged_in();
}
public function index() {
echo 'hello';
}
}
Run Code Online (Sandbox Code Playgroud)
我只想在用户登录时使控制器内的功能可访问.
这是自动加载的帮助程序
$autoload['helper'] = array('url','array','html','breadcrumb','form','function','accesscontrol');
Run Code Online (Sandbox Code Playgroud)
(accesscontrol_helper.php):
<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');
function is_logged_in()
{
$is_logged_in = $this->session->userdata('is_logged_in');
if(!isset($is_logged_in) || $is_logged_in …Run Code Online (Sandbox Code Playgroud) 当var_dump时,我有一个类似于以下内容的数组:
array(3) { [0]=> array(3) { ["id"]=> string(1) "3" ["category"]=> string(5) "staff" ["num_posts"]=> string(1) "1" } [1]=> array(3) { ["id"]=> string(1) "1" ["category"]=> string(7) "general" ["num_posts"]=> string(1) "4" } [2]=> array(3) { ["id"]=> string(1) "2" ["category"]=> string(6) "events" ["num_posts"]=> string(1) "1" } }
Run Code Online (Sandbox Code Playgroud)
'如果数组不包含以下字符串,我需要回显一个值:'hello'
这怎么可能,我尝试过使用in_array,但没有成功.帮助赞赏.
我有一个配置文件: application/config/breadcrumbs.php
在文件中我有以下配置项:
$config['hide_number'] = TRUE;
Run Code Online (Sandbox Code Playgroud)
如何通过控制器更改此配置项的值.
我只需要更改此配置项的值一次.怎么做的???
我在codeigniter中有一系列复选框,需要在提交表单时显示已检查的状态和值.
我怎样才能做到这一点??我已经阅读了codeigniter网站的文档,但看不到如何设置检查状态?
这是我的代码:
<?php echo form_checkbox('spa', 'y', FALSE, '') ?>
Run Code Online (Sandbox Code Playgroud) 我想知道人们在我的网站上查看我的用户个人资料的次数.
我想在我的数据库中保持计数,并在用户刷新页面时停止计数递增.按IP限制.
我知道需要每天创建和清空一个ip地址缓存.
有没有关于如何做到这一点的指示.谁能跟我说话呢?