不显示查看页面
我不知道如何做到这一点,因为它没有回显我的 html。它在 firebug 中显示 div 标签,但后面没有任何其他内容,应该是索引页面(主页)或我的 404 页面。应该发生的事情是它应该通过 if 语句找出应该加载哪个页面视图,然后在内容页面内加载该视图。
控制器:
$siteInfo = $this->kow->getSiteTitleAndSlogan();
$activeTemplate = $this->kow->getTemplate();
if ($this->kow->pageStatus('index', $activeTemplate[0]->short_name) == 1){
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/index');
} else {
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/404');
}
$footerLinks = $this->kow->getFooterNav();
$this->template
->title($siteInfo[0]->site_name,$siteInfo[0]->site_slogan)
->prepend_metadata('<link rel="stylesheet" type="text/css" href="http://www.kansasoutlawwrestling.com/assets/css/'.$activeTemplate[0]->short_name.'.css" />')
->set('footerLinks', $footerLinks)
->set('page', $page)
->set_partial('header', $activeTemplate[0]->short_name.'/header')
->set_partial('navigation', $activeTemplate[0]->short_name.'/navigation')
->set_partial('content', $activeTemplate[0]->short_name.'/content')
->set_partial('footer', $activeTemplate[0]->short_name.'/footer')
->build('kow');
if ($this->kow->pageStatus('index', $activeTemplate[0]->short_name) == 1){
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/index');
} else {
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/404');
}
视图:
<div id="content">
<?php
echo $page;
?>
</div>
编辑:我想要做的是将活动模板的 id 和 pageStatus 函数的字符串索引,并找出页面状态的值是否为 1。当我运行 print_r 函数时就像下面我得到这个:
Array ( [0] => Array ( [status_id] => 1 ) )
控制器
if ($this->kow->pageStatus('index', $activeTemplate[0]->id) == 1){
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/index', '', true);
} else {
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/404', '', true);
}
print_r($this->kow->pageStatus('index', $activeTemplate[0]->id));
编辑2:我仍然没有得到正确的页面来查看。
I'm not sure how to do this because its not echoing my html. Its showing the div tag in firebug but not anything else after it which should be either the index page(homepage) or my 404 page. What's supposed to happen is its supposed to find out which page view its supposed to load via the if statement and then load load that view inside the content page.
Controller:
$siteInfo = $this->kow->getSiteTitleAndSlogan();
$activeTemplate = $this->kow->getTemplate();
if ($this->kow->pageStatus('index', $activeTemplate[0]->short_name) == 1){
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/index');
} else {
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/404');
}
$footerLinks = $this->kow->getFooterNav();
$this->template
->title($siteInfo[0]->site_name,$siteInfo[0]->site_slogan)
->prepend_metadata('<link rel="stylesheet" type="text/css" href="http://www.kansasoutlawwrestling.com/assets/css/'.$activeTemplate[0]->short_name.'.css" />')
->set('footerLinks', $footerLinks)
->set('page', $page)
->set_partial('header', $activeTemplate[0]->short_name.'/header')
->set_partial('navigation', $activeTemplate[0]->short_name.'/navigation')
->set_partial('content', $activeTemplate[0]->short_name.'/content')
->set_partial('footer', $activeTemplate[0]->short_name.'/footer')
->build('kow');
if ($this->kow->pageStatus('index', $activeTemplate[0]->short_name) == 1){
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/index');
} else {
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/404');
}
View:
<div id="content">
<?php
echo $page;
?>
</div>
EDIT: What I'm trying to do is take the id of the active template and the string index to the pageStatus function and find out if the status of the page has a value of 1. When I run the print_r function like below I get this:
Array ( [0] => Array ( [status_id] => 1 ) )
Controller
if ($this->kow->pageStatus('index', $activeTemplate[0]->id) == 1){
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/index', '', true);
} else {
$page = $this->load->view($activeTemplate[0]->short_name.'/pages/404', '', true);
}
print_r($this->kow->pageStatus('index', $activeTemplate[0]->id));
EDIT 2: I'm still not getting the right page to view.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您将索引和 404 的视图错误地加载到
$page
变量中。要存储$this->load->view()
调用的输出,您必须包含true
作为第三个参数。来自 CI 用户指南
以数据形式返回视图
第三个可选参数可让您更改函数的行为,以便它以字符串形式返回数据,而不是将其发送到浏览器。如果您想以某种方式处理数据,这可能很有用。如果将参数设置为 true(布尔值),它将返回数据。默认行为为 false,将其发送到您的浏览器。如果您希望返回数据,请记住将其分配给变量:
此外,代码的最后一位,
$page
的第二个定义发生在调用->set(' page', $page)
和->build('kow');
因此不会改变输出。You're loading the views for index and 404 into the
$page
variable incorrectly. To store the output of a$this->load->view()
call you must includetrue
as the third parameter.From the CI user guide
Returning views as data
There is a third optional parameter lets you change the behavior of the function so that it returns data as a string rather than sending it to your browser. This can be useful if you want to process the data in some way. If you set the parameter to true (boolean) it will return data. The default behavior is false, which sends it to your browser. Remember to assign it to a variable if you want the data returned:
Also, the last bit of your code, the second definition of
$page
happens after the call to->set('page', $page)
and->build('kow');
which therefore won't change the output.我对代码点火器一无所知,但据我所知。我认为 $page 可能是一个 TEMPLATE 对象,并且它不应该使用 ECHO 自然显示...
或者
您的模板由于 php 致命错误而无法呈现,但这就是为什么您的缓冲区包含初始 DIV 而没有其他内容。 (或者在 ECHO $PAGE 处理过程中调用了 EXIT/DIE)
I don't know anything about code igniter, but as i see this. I think $page might be a TEMPLATE object and it is not meant to be displayed using ECHO naturaly...
OR
Your template fails to render because of a php fatal error but so thats why your buffer contains the initial DIV but nothing else. (Or an EXIT/DIE was called within processing of your ECHO $PAGE)
这个“$this->kow->pageStatus('index', $activeTemplate[0]->id)”返回一个数组。无法与您的做法进行比较。当然它会返回 1,这可以解释为 TRUE,但是如果 status_id 设置为 0 或 2 或其他值,那么它仍然会返回“TRUE”。
希望这有帮助
This "$this->kow->pageStatus('index', $activeTemplate[0]->id)" returns an array. Cant compare it in the way your doing it. Sure it will return 1 which can be interpreted as TRUE but what if the status_id is set to 0 or 2 or something else then it will still return "TRUE".
Hope this helps