如何将CakePHP视图的扩展名从.ctp更改为.php
我已经看到/cake/libs/view.php var $ext = '.ctp';中有这一行设置了扩展名,但是如何从我的/ app /文件夹中执行此操作,因此它不会影响Cake核心文件.
谢谢
我有这个代码应该显示一个数组列表,后面跟一个逗号和空格!但是我不希望最后一个在它之后有逗号和空格.
所以例如我想要tag1, tag2, tag3而不是tag1, tag2, tag3,
这是我的代码:
<?php $terms = get_the_terms( $the_post->ID, 'posts_tags' );
foreach ( $terms as $term ) {
echo $term->name;echo ", ";
} ?>
Run Code Online (Sandbox Code Playgroud) 我如何传递日期时间,例如01/01/2011 21:01:34作为查询字符串?
我正在建立一个剧院预订网站,当我观看表演时,我目前通过了演出和场地,但也需要通过日期(因为这是演出的独特部分)
ActionResult看起来像这样:
public ActionResult Details(String name, String venue, String date)
{
return View(_repository.performanceDetails(name, venue, date));
}
Run Code Online (Sandbox Code Playgroud)
但是performanceDate不会工作,因为它是一个日期时间数据类型!我需要做的是删除数据的时间部分,例如00:00:00并以某种方式将剩余数据作为字符串传递,我可以用它来比较,如下所示:
public PerformanceDetails performanceDetails(String name, String venue, String date)
{
var PerformanceDetails = (from s in _db.PerformanceDetails
where s.show == name &&
s.venue == venue &&
s.performanceDate == date
select s).First();
return PerformanceDetails;
}
Run Code Online (Sandbox Code Playgroud)
这是一个示例链接:
<%= Html.ActionLink("View Details", "Details", "Performances",
new {
name = item.show,
venue = item.venue,
date = item.performanceDate },
new {@class = "button"}) …Run Code Online (Sandbox Code Playgroud) 我有以下代码:
$('a.uiPopup').hover(function () {
$('.uiTip').show();
},
function () {
$('.uiTip').remove();
});
$('div.uiTip').live("mouseover", function () {
$(this).stop(true, true).show();
});
$('div.uiTip').live("mouseleave", function () {
$(this).remove(); });
});
Run Code Online (Sandbox Code Playgroud)
所以当你悬停uiPopup然后uiTip出现然后当你解开时它再次消失但是如果你将鼠标悬停在尖端上它会阻止尖端被移除并将其保持在屏幕上直到你的鼠标离开然后将其移除.
虽然不起作用:/任何想法?谢谢
这.remove()是故意在我的真实脚本(这是一个显示我的例子的片段)我使用AJAX加载.uiHelp并且他们有unqiue id(再次没有在上面的例子中显示超出问题的范围)当用户悬停尖端本身时,工作得很好,而不是停止它!
编辑:对于那些想要查看完整脚本以及为什么我必须使用悬停的人:
$('a.uiPopup').hover(function () {
$tip = '<div class="uiTip uiOverlayArrowLeft loading"><div class="uiOverlayContent"><!--content here --></div><i class="uiOverlayArrow"></i></div>';
$newtip = $($tip).attr('id', 'organisationId-' + $(this).attr('id'));
$($newtip).find('.uiOverlayContent').load(AppURL + 'Organisations/Manage/Tip', function () { $($newtip).removeClass('loading') });
$('body').append($newtip);
$location = $(this).offset(); $top = $location.top; $left = $location.left; $right = $location.right; $bottom = $location.bottom;
$left …Run Code Online (Sandbox Code Playgroud) 如果我有类似的东西:
App = {
editingMode: function ()
{
function setEditingMode(entityID) {
$('#editingMode').val('1');
$.ajax({
type: "POST",
url: "/Organisations/Manage/LockEntity/",
data: "entityID=" + entityID
});
}
function setEditingModeOff(entityID) {
if ($("#myform").valid() == true)
{
$('#editingMode').val('0');
$.ajax({
type: "POST",
url: "/Organisations/Manage/UnlockEntity/",
data: "entityID=" + entityID
});
}
}
}
};
Run Code Online (Sandbox Code Playgroud)
我如何运行其中一个内部函数?
App.editingMode();但那我该怎么办呢setEditingMode?
我有以下jQuery代码:
var shown = $('div.slideshow').find('div.slide:visible');
var next = shown.next();
if(next == '') {
console.log('empty');
}
Run Code Online (Sandbox Code Playgroud)
基本上当下一个像空时一样回来时:[]我希望能够检测到这一点.我该怎么做?
我为CakePHP应用程序构建了一个简单的测试API,允许用户从移动设备(或任何设备)登录并获得JSON响应.此API可用于内置PhoneGap的移动应用.
登录方法如下所示:
public function login()
{
if($this->request->is('post'))
{
// Use custom method in Model to find record with password params
$findUser = $this->User->findUser(
$_POST['username_or_email'],
AuthComponent::password($_POST['password'])
);
// If a user exists and matches params
if($findUser)
{
$this->User->id = $findUser['User']['id'];
$this->autoRender = false;
$this->response->type('json');
$this->response->body(json_encode(array('authenticated'=>true,'message'=>__('You have been logged in successfully'))));
}
else
{
$this->autoRender = false;
$this->response->type('json');
$this->response->body(json_encode(array('authenticated'=>false,'message'=>__('Username or password is incorrect'))));
}
}
else
{
$this->autoRender = false;
$this->response->type('json');
$this->response->body(json_encode(array('message'=>'GET request not allowed!')));
}
}
Run Code Online (Sandbox Code Playgroud)
移动设备(或任何API用户)可以发送他们的登录详细信息,然后他们将JSON的请求作为true或false获取,以进行身份验证.这个布尔值不用于给用户访问,而是告诉移动应用程序他们是否可以看到某些屏幕,他们只能获取数据,或者如果会话存在则可以发送数据!
如上所述,它们实际上也是在设备上登录API本身,因此如果他们直接访问网站(从该设备),他们将有一个会话并看到相同的JSON响应.
因此,基本上用户在与服务器通信的设备上保持登录的持续时间.这与需要为每个请求传递的令牌不同,在此示例中,它们具有会话.
现在问题...... …
我在这里使用history.js插件:https://github.com/browserstate/history.js/用于处理我的应用程序中的HTML5历史记录.我想处理二者 HTML5和HTML4的版本(使用散列后备).
你可以在这里看到演示:http://dev.driz.co.uk/history45/
当一个人访问带有哈希的网址时(如果没有点击网站上的链接),我如何根据哈希加载正确的内容?因为服务器将无法理解代码是什么,我不想必须通过检查哈希是否存在然后通过AJAX调用内容来使请求加倍.例如:http://dev.driz.co.uk/history45/#about.php不加载about.php内容.
更新:
我在这里看到了一些例子:https://gist.github.com/balupton/858093这似乎涵盖了加载正确的内容(甚至是优化版本).但我正在努力让它与我的HTML5版本结合使用.查看源:http://dev.driz.co.uk/history45/它只在个人点击链接而不是页面加载时运行,这是原始问题.
更新2:
在这里尝试了一个例子:http://dev.driz.co.uk/history4/#/contact.php,使用源代码中的代码段来获取要在contact.php内容中加载的内容,但是不起作用......?但根据这篇文章:https://github.com/browserstate/history.js/wiki/Intelligent-State-Handling#wiki-why-the-hashbang-is-unnecessary这段代码应该是AJAX加载正确的内容如果它有哈希值.有什么想法吗?
如何强制/#/在root上并使用`#/'为所有URL添加前缀
目前,如果您尝试通过HTML4浏览器中的链接访问页面,您最终会得到如下奇怪的网址:
http://dev.driz.co.uk/history45/#contact.php 和 http://dev.driz.co.uk/history45/#./
代替:
http://dev.driz.co.uk/history45/#/contact.php 和 http://dev.driz.co.uk/history45/#/
如果我从内页开始:
http://dev.driz.co.uk/history45/contact.php并选择一个链接然后我最终得到:http://dev.driz.co.uk/history45/contact.php#about.php当它应该是什么时:http://dev.driz.co.uk/history45/#/about.php
我正在使用AngularJS和ui-router,并使用以下代码捕获404并在404模板中加载:
$urlRouterProvider.otherwise(function($injector, $location){
$injector.invoke(['$state', function($state) {
$state.go('404');
}]);
});
Run Code Online (Sandbox Code Playgroud)
它保持URL完整而不是重定向,但显示404模板:
.state('404',
{
views: {
'body': {
templateUrl: 'partials/404.html',
}
}
});
Run Code Online (Sandbox Code Playgroud)
通常它会重定向到根状态: $urlRouterProvider.otherwise('/');
但是,当关闭HTML5模式并且用户访问根URL时,例如http://www.domain.com/app/它加载404状态而不是重定向到http://www.domain.com/app/#/
如何保持上面的404状态代码,但在访问初始页面时将其重定向到hashbang?如果请求不是主页,那么只有404加载才有效吗?
我不能使用$stateNotFound或$stateChangeSuccess并需要一种方法来检查它是否是实际的配置设置本身可以在切换中的主页请求/和state.404否则语句中.
在我的Rails应用程序I Pages,Blocks,BlockContents,Fields和FieldContents中.
协会是:
class Page < ActiveRecord::Base
has_many :blocks
has_many :block_contents, :through => :blocks
end
class Block < ActiveRecord::Base
belongs_to :page
has_many :block_contents
end
class BlockContent < ActiveRecord::Base
belongs_to :block
has_many :field_contents
end
class Field < ActiveRecord::Base
has_many :field_contents
end
class FieldContent < ActiveRecord::Base
belongs_to :block_content
belongs_to :field
validates :content, presence: true
end
Run Code Online (Sandbox Code Playgroud)
使用这个,我可以为Page拥有动态字段.
但是,写入DB当前是在控制器中完成的,如下所示:
def update
@page = Page.find(params[:id])
if params[:field_content].present?
params[:field_content].each do |block_content|
block_content.last.each do |field|
field_content_row = FieldContent.where(block_content_id: block_content.first, field_id: field.first).first
if field_content_row.present?
field_content_row.update(content: field.last)
else
field_content …Run Code Online (Sandbox Code Playgroud) javascript ×3
jquery ×3
cakephp ×2
angularjs ×1
api ×1
arrays ×1
asp.net-mvc ×1
history.js ×1
html5 ×1
php ×1