小编vet*_*982的帖子

CakePHP将列添加到表中

我的蛋糕应用程序中有一个Profile模型/控制器,以及/ views/profiles中的index.ctp视图.现在,当我向我的表中添加一个已填充数据的列,然后将相应的代码添加到视图中以获取此列的数据时,它只是给我一个空结果.

我的模特:

<?php
        class Profile extends AppModel
        {
                var $name = 'Profile';
        }

?>
Run Code Online (Sandbox Code Playgroud)

我的控制器:

<?php
        class ProfilesController extends AppController
        {
                var $name = 'Profiles';
                function index()
                {
                        $this->set('profiles', $this->Profile->find('all'));
                }
        }
?>
Run Code Online (Sandbox Code Playgroud)

我的观点打印(剥离):

<?php foreach ($profiles as $profile): ?>

<?php echo $profile['Profile']['id']; ?>
<?php echo $profile['Profile']['username']; ?>
<?php echo $profile['Profile']['created']; ?>
<?php echo $profile['Profile']['thumbnail'];?>
<?php echo $profile['Profile']['account'];?>

<?php endforeach; ?>
Run Code Online (Sandbox Code Playgroud)

基本上,columns id, username, column, thumbnail总是打印得很好,但是当我添加一个名为account它的列时,它不返回任何信息(没有打印,但没有错误).有什么建议?

php sql frameworks cakephp

3
推荐指数
1
解决办法
3897
查看次数

将类功能与其实际功能分开声明有什么好处?

在C++中,拥有一个具有函数的类有什么好处......

class someClass{
 public:
  void someFunc(int arg1);
};
Run Code Online (Sandbox Code Playgroud)

然后在int main之后声明函数的实际功能

int main() 
    { return 0; }

void someClass::someFunc(int arg1)
    {   cout<<arg1; }
Run Code Online (Sandbox Code Playgroud)

此外,在.h头文件中声明类,然后将功能放在#include .h文件的.cpp文件中有什么好处?

c c++ oop class function

1
推荐指数
1
解决办法
181
查看次数

Java的compareTo()函数在Perl中是等价的吗?

compareTo在Java 中实现与()相同的Perl函数是什么?我知道eqne,但我想比较一下,看一个字符串是否大于另一个.

java perl function compareto

1
推荐指数
2
解决办法
292
查看次数

使用带有C和非顶级URL的cURL时出现问题

我正在使用cURL来抓取网页,但我似乎只能抓取顶级网址.例如,如果我想查询URL" http://www.businessweek.com/news/2010-09-29/flaherty-says-canada-july-gdp-report-tomorrow-may-be-negative.html "然后它什么都不返回(好像它是一个空白页面).

这是我的C代码:

#include <stdio.h>
#include <curl/curl.h>

int main(void)
{
  CURL *curl;
  CURLcode res;

  curl = curl_easy_init();
  if(curl) {
//THIS WORKS
//curl_easy_setopt(curl, CURLOPT_URL, "news.google.com"); 

//THIS DOESN'T WORK
  curl_easy_setopt(curl, CURLOPT_URL, "http://www.businessweek.com/news/2010-09-29/flaherty-says-canada-july-gdp-report-tomorrow-may-be-negative.html"); 
    res = curl_easy_perform(curl);

    curl_easy_cleanup(curl);
  }
  return 0;
}
Run Code Online (Sandbox Code Playgroud)

如果我能在这个问题上得到一些很好的意见.

c url curl libcurl

1
推荐指数
1
解决办法
138
查看次数

sizeof内联结构声明

如果有一个结构带有指向其中声明的结构的指针,那么如何确定子结构的大小?

typedef struct myStruct {
  int member;
  struct subStruct {
    int a;
    int b;
  } *subStruct_t;
} myStruct_t;
Run Code Online (Sandbox Code Playgroud)

你如何为subStruct_t指针分配空间?我正在思考一些事情

myStruct_t M;
M.subStruct_t = calloc(1,sizeof(myStruct_t.subStruct_t);
Run Code Online (Sandbox Code Playgroud)

但它显然不起作用.有任何想法吗?

c c++ memory

1
推荐指数
1
解决办法
593
查看次数

无法在包含sleep()的循环中写入文件

我的问题的本质是我无法使用sleep()在循环中写入文件.如果我有以下代码:

ofstream file
file.open("file.name");

for(;;) {
    file << "HELLO\n";
}
Run Code Online (Sandbox Code Playgroud)

此代码完美运行并将HELLO重复打印到"file.name".但是,我想做这样的事情(我正在记录来自实时应用程序的数据):

for(;;) {
    file << "HELLO\n";
    sleep(1);
}
Run Code Online (Sandbox Code Playgroud)

这似乎不会在我的文件中打印任何内容.有任何想法吗?

c++ fstream file

0
推荐指数
1
解决办法
558
查看次数

标签 统计

c ×3

c++ ×3

function ×2

cakephp ×1

class ×1

compareto ×1

curl ×1

file ×1

frameworks ×1

fstream ×1

java ×1

libcurl ×1

memory ×1

oop ×1

perl ×1

php ×1

sql ×1

url ×1