在我的自定义模块中,我想添加注释功能.我尝试了几件事,但到目前为止还没有锻炼.
// render comments form
$output .= theme('my_module_front_page');
$comment = new stdClass;
$comment->nid = $node_good_practice->nid;
$output .= render(drupal_get_form('comment_form', $comment));
return $output;
Run Code Online (Sandbox Code Playgroud)
上面的代码将注释表单放到我的节点页面.
但是当我填写评论表并提交时,它会将我重定向到这个页面:comment/reply/node id然后我必须重新填写我的评论并且评论不会被保存.
我想提交并保持在同一页面而不是重定向.提交后必须保存评论.
现在,评论表单出现在我的节点页面(自定义模块模板)上.我输入评论并点击"保存".我被发送到/comment/reply/<node_id>,但所有评论字段都是空的.评论也没有保存.
我想要发生的是:
添加重定向
$form['#redirect'] = "/success-stories/".$node_good_practice->good_practice_name."/".$node_good_practice->nid;
Run Code Online (Sandbox Code Playgroud)
它没有改变任何东西.
改变行动
$form['#action'] = "/success-stories/".$node_good_practice->good_practice_name."/".$node_good_practice->nid;
Run Code Online (Sandbox Code Playgroud)
它将我重定向到 node/node_id/#comment-17
使用 drupal_build_form()
$info->nid = $node_good_practice->nid;
$comment['build_info']['args'][0] = $info;
$comment['redirect'] = "http://www.google.nl";
$output .= render(drupal_build_form('comment_form', $comment));
Run Code Online (Sandbox Code Playgroud)
表单正在显示,但不会重定向; 它发送给comment/reply/node_id.
编写功能测试和DOMCrawler时遇到问题.我的问题是通过链接抓取邮件内容.从文档中我看到可以使用html内容作为参数创建爬虫.所以这是我的代码块:
$mailCrawler = new Crawler($message->getBody());
$linkCrawler = $mailCrawler->selectLink('Link name');
$client->click($linkCrawler->link());
Run Code Online (Sandbox Code Playgroud)
在第三行,我有一个例外,因为$ linkCrawler有空的$ uri字段.异常消息:
InvalidArgumentException: Current URI must be an absolute URL ("").
Run Code Online (Sandbox Code Playgroud)
任何人都可以告诉我为什么爬虫不能获得该链接?
我只能告诉$ message var getBody方法返回正确的内容.
问候
我有两个不同的字符串:
("宝贝"或"14%"或"十"可以改变,所以我不能指定它们)
我想识别该字符串中的日期,我试过:
$dt = date_parse($string);
Run Code Online (Sandbox Code Playgroud)
在第一种情况下,没关系,但在第二种情况下,它无法识别日期.
我试过没有成功
$dt = date_parse_from_format("d.m.Y", $string);
Run Code Online (Sandbox Code Playgroud)
我尝试使用preg_match或preg_match_all但没有成功(我不是很擅长).