我是cakephp的新手并且遵循本教程. http://book.cakephp.org/2.0/en/tutorials-and-examples/blog-auth-example/auth.html
我创建了博客和用户身份验证系统.我正在尝试显示登录链接(如果用户未登录)或显示退出链接(如果用户已登录).
所以,基本上我正在检查会话是否已设置.如果是,则显示注销链接.如果未设置会话,则显示要登录的链接.
这是在我的文件index.ctp中,位于View/Posts/index.ctp中.包含登录和注销功能的文件位于Controller/UsersController.php中.
<?php
if($this->Auth->User('id')){
echo $this->Html->link('Log Out', array('controller' => 'users','action' => 'logout'));
}
if(!($this->Auth->User('id'))){
echo $this->Html->link('Log In', array('controller' => 'users','action' => 'login'));
}
?>
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:致命错误:在非对象上调用成员函数User().我知道这意味着对象没有定义,但我不知道如何将它引用到另一个控制器.
谢谢你的帮助.
我正在尝试使用Tkinter获取目录的完整路径,但只显示目录名称.
例如,当我选择"C:\ Python27\Doc"时,而不是显示的完整路径,只显示"Doc".
class Actions:
def openfile(self): #open the file
directory = tkFileDialog.askdirectory()
print(directory)
def body(self):
Label (text='Please select a directory').pack(side=TOP,padx=10,pady=10)
Run Code Online (Sandbox Code Playgroud)
我找到了这个http://tkinter.unpythonic.net/wiki/tkFileDialog,但除非我误解了它,否则我看不到任何完整路径.
有没有比删除特定键的值然后重新输入新信息更简单的方法来更改tkinter列表框中的项目顺序?
例如,我希望能够重新排列列表框中的项目。如果我想交换两个职位,这就是我所做的。它可行,但是我只想看看是否有更快的方法可以做到这一点。
def moveup(self,selection):
value1 = int(selection[0]) - 1 #value to be moved down one position
value2 = selection #value to be moved up one position
nameAbove = self.fileListSorted.get(value1) #name to be moved down
nameBelow = self.fileListSorted.get(value2) #name to be moved up
self.fileListSorted.delete(value1,value1)
self.fileListSorted.insert(value1,nameBelow)
self.fileListSorted.delete(value2,value2)
self.fileListSorted.insert(value2,nameAbove)
Run Code Online (Sandbox Code Playgroud) 任何人都可以指出我在哪里可以找到有关制作列表框的信息,能够拖放项目进行重新安排?我发现了一些与Perl相关的内容,但我对这种语言一无所知,而且我对tkinter很新,所以这很让人困惑.我知道如何生成列表框,但我不知道如何通过拖放重新排序.
我在使用 Tkinter 和 Python 的网格使所有内容正确排列时遇到一些麻烦。我希望菜单栏位于最顶部,然后有两个列表框(每一侧一个),在窗口中间它们之间有几个按钮。
目前,两个列表框都出现在窗口的右下角,按钮位于左上角,与菜单按钮重叠。
考虑到列表框的大小,如何处理列表框的网格布局。它们可以占据多个网格单元吗?例如,如果我将一个列表框放在 (row = 1,column = 1) 中,另一个放在行 (row = 1,column = 2) 中,Tkinter 会自动加宽单元格,使其成为列表框的宽度,还是会只是重叠列表框?
def __init__(self,root):
self.frame = Frame(root, width=500)
self.frame.pack()
self.BuildMainWindow(self.frame)
self.ListboxSet = 0
self.frame.grid()
return
#displays the menu bar and options
def BuildMainWindow(self, frame):
menubar = Frame(frame,relief=RAISED,borderwidth=1)
menubar.pack()
mb_file = Menubutton(menubar,text='file')
mb_file.menu = Menu(mb_file)
mb_file.menu.add_command(label='open', command = self.openfile)
mb_file.grid(row = 1, column = 1)
mb_edit = Menubutton(menubar,text='edit')
mb_edit.menu = Menu(mb_edit)
mb_edit.grid(row=1, column = 3)
mb_file['menu'] = mb_file.menu
mb_edit['menu'] = mb_edit.menu
#upon selecting …Run Code Online (Sandbox Code Playgroud) I'm running OS X Sierra and trying to compile a c program that uses strcpy_s, but my installed clang compiler is using the c99 standard, but from what I've read strcpy_s requires c11.
Here's the code I'm trying to compile
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
int main(void)
{
char source[] = "Test string";
char destination[50];
if(strcpy_s(destination, sizeof(destination), source))
printf("string copied - %s",destination);
return 0;
}
Run Code Online (Sandbox Code Playgroud)
And here's the command I'm using to compile
$ clang copytest.c -o copytest …Run Code Online (Sandbox Code Playgroud) 我正在尝试创建一个用户表,这是一个组的一部分,但我似乎无法让它工作.该列表存储在一列中,以便每个用户ID#由"〜"分隔.例如,如果用户1,2和3正在参加该列将显示"1~2~3".这就是我用来爆炸的东西.
我收到以下错误"警告:mysql_fetch_array()期望参数1是资源,布尔值在"哪个是定义$ friend的行.
$attendingUsers = mysql_query("Select acceptedInvites from events where eventID = ".$_GET['eventID']." ");
while($friend = mysql_fetch_array($attendingUsers)){
$users = $friend['acceptedInvites'];
$userExplode = explode("~",$users);
for($i=0; $i<count($userExplode);$i++){
echo $userExplode[$i]; //displays the userid number properly so I know this is working
$friendInfo = mysql_query("select (userid,username) from users where userid = '". $userExplode[$i]."' ");;
$friend = mysql_fetch_array($friendInfo);
echo '<table><tr><td><a href="profile.php?userid=' . $friend['userid'] . '">' . $friend['username'] . '</a></td>';
}
}
Run Code Online (Sandbox Code Playgroud)
我开始认为它与$ friendInfo有关,因为当我回显它时,没有显示任何内容(通常会说数组).
是否可以在MySQL查询中使用if语句,类似于我所显示的内容?我想获取即将发生的事件的一些信息(不是以前的日期).
ini_set('date.timezone', 'America/New_York');
echo $timestamp = date('Y-m-d');
$sql = "select eventID,eventTitle,eventDate from events where eventLocationID = $locationID AND (eventDate > $timestamp) ORDER BY eventDate ASC";
Run Code Online (Sandbox Code Playgroud)
编辑 - sql语句没有过滤掉今天之前的日期(它显示了所有内容).
例如,我正在回应时间戳,以确保它正确设置.在我的桌子上,我输入了两个日期,一个在一月,一个在今天.
所以这是输出
2012-05-31 //timestamp, not part of results. just for reference
2012-01-10 //first result, however it shouldn't display
2012-06-22 //this should be the only result that displays
Run Code Online (Sandbox Code Playgroud) 我正在尝试从文本文件中读取最后一行.每行以数字开头,因此下次插入某些内容时,新数字将增加1.
例如,这将是一个典型的文件
1. Something here date
2. Something else here date
#next entry would be "3. something date"
Run Code Online (Sandbox Code Playgroud)
如果文件为空,我可以输入一个没有问题的条目.但是,当已经有条目时,我收到以下错误
LastItemNum = lineList[-1][0:1] +1 #finds the last item's number
TypeError: cannon concatenate 'str' and 'int objects
Run Code Online (Sandbox Code Playgroud)
这是我的功能代码
def AddToDo(self):
FILE = open(ToDo.filename,"a+") #open file for appending and reading
FileLines = FILE.readlines() #read the lines in the file
if os.path.getsize("EnteredInfo.dat") == 0: #if there is nothing, set the number to 1
LastItemNum = "1"
else:
LastItemNum = FileLines[-1][0:1] + 1 #finds the …Run Code Online (Sandbox Code Playgroud) 我无法使用python/tkinter获取事件绑定.我只是想点击并打印位置,但每次我这样做,结果都是"-1".
这是我的代码
from Tkinter import *
import Tkinter
class make_list(Tkinter.Listbox):
def __init__(self,master, **kw):
frame = Frame(master)
frame.pack()
self.build_main_window(frame)
kw['selectmode'] = Tkinter.SINGLE
Tkinter.Listbox.__init__(self, master, kw)
master.bind('<Button-1>', self.click_button)
master.curIndex = None
#display the clicked location
def click_button(self, event):
self.curIndex = self.nearest(event.x)
print self.curIndex
#display the window, calls the listbox
def build_main_window(self, frame):
self.build_listbox(frame)
#listbox
def build_listbox(self, frame):
listbox = Listbox(frame)
for item in ["one", "two", "three", "four"]:
listbox.insert(END, item)
listbox.insert(END, "a list entry")
listbox.pack()
return
if __name__ == '__main__':
tk = Tkinter.Tk() …Run Code Online (Sandbox Code Playgroud) 我正在尝试选择介于2个日期之间的值,因此我将不得不使用<=和> =,但是,我的查询看起来似乎只是小于或大于并且不考虑等于日期的值.
我正在使用CakePHP,以"Ymd h:i:a"格式保存日期.我想在给定的一周间隔(从星期日开始)找到日期,所以我使用了以下内容.
$start_date = date('Y/m/d', strtotime('last Sunday', strtotime($timestamp)));
$formatted_start_date = str_replace("/","-",$start_date);
Run Code Online (Sandbox Code Playgroud)
我试图将$ start_date格式化为"Ymd",但之后它找不到正确的日期,所以我将其切换到它的方式并使用str_replace将其格式化为使用" - "而不是"/".
$date_query = $this->Order->query("select * from orders where id = '$id' and created => '$formatted_start_date' and created <= '$current_timestamp' ");
Run Code Online (Sandbox Code Playgroud)
考虑到我的数据库中的时间值是"Ymd h:i:a"格式,我可以使用"Ymd"进行日期比较吗?是否可以执行涉及LIKE和<=的MySQL查询?