我正在使用jQuery编辑我在Symfony中构建的表单.
我在jQuery对话框中显示该表单,然后提交它.
数据在数据库中正确输入.
但我不知道是否需要将一些JSON发送回jQuery.其实我对JSON的事情有点困惑.
假设我在我的表中添加了一行jQuery,当我提交表单然后提交数据后,我想发回那些行数据,以便我可以动态添加表行来显示添加的数据.
我很困惑如何才能获得这些数据
这是我目前的代码
$editForm = $this->createForm(new StepsType(), $entity);
$request = $this->getRequest();
$editForm->bindRequest($request);
if ($editForm->isValid()) {
$em->persist($entity);
$em->flush();
return $this->render('::success.html.twig');
}
Run Code Online (Sandbox Code Playgroud)
这只是带有成功消息的模板
array_key_exists不适用于大型多维数组.对于前者
$arr = array(
'1' => 10,
'2' => array(
'21' => 21,
'22' => 22,
'23' => array(
'test' => 100,
'231' => 231
),
),
'3' => 30,
'4' => 40
);
Run Code Online (Sandbox Code Playgroud)
array_key_exists('test',$ arr)返回'false'但它适用于一些简单的数组.
我想用JMSSerializerBundle手动完成JSON.HandlerCallback遇到了一些麻烦.这是一个代码:
namespace Company\Bundle\Model;
use JMS\Serializer\Annotation\Type;
use JMS\Serializer\Annotation\SerializedName;
use JMS\Serializer\Annotation\HandlerCallback;
use JMS\Serializer\JsonDeserializationVisitor;
use JMS\Serializer\DeserializationContext;
use JMS\Serializer\TypeParser;
use JMS\Serializer\Serializer;
class Blog
{
protected $blogName;
protected $blogUrl;
protected $blogCategory;
/**
* @Type("array<Company\Bundle\Model\Post>")
* @SerializedName("data")
*/
protected $posts;
/**
* @param mixed $posts
*/
public function setPosts($posts)
{
$this->posts = $posts;
}
/**
* @return mixed
*/
public function getPosts()
{
return $this->posts;
}
/**
* @HandlerCallback("json", direction = "deserialization")
*/
public function deserializeFromJson(JsonDeserializationVisitor $visitor, array $data, DeserializationContext $context)
{
$this->blogName = $data['data'][0]['blogName'];
$this->blogUrl …Run Code Online (Sandbox Code Playgroud) 我有一个Symfony控制器的通用结构(使用FOSRestBundle)
/**
* @Route\Get("users/{id}", requirements={"userId" = "(\d+)"})
*/
public function getUserAction(User $user)
{
}
Run Code Online (Sandbox Code Playgroud)
现在,如果我要求http://localhost/users/1一切都很好.但如果我要求http://localhost/users/11111111111111111我得到500错误和异常
ERROR: value \"11111111111111111\" is out of range for type integer"
Run Code Online (Sandbox Code Playgroud)
有没有办法在ID传输到数据库之前检查?
作为解决方案,我可以指定id的长度
/**
* @Route\Get("users/{id}", requirements={"userId" = "(\d{,10})"})
*/
Run Code Online (Sandbox Code Playgroud)
但是Symfony会说没有这样的路线,而不是表明id不正确.
我这样做:
$data = array('coords' => $district->getCoords(),
'id' => $district->getId(),
'fid' => $district->getFid(),
'wijziging'=> $district->getWijziging(),
'nieuwnr' => $district->getNieuwnr(),
'naam' => $district->getNaam(),
'wijk' => $district->getWijk(),
'wijknr' => $district->getWijknr(),
'objectid' => $district->getObjectid(),
'area' => $district->getArea(),
'len' => $district->getLen(),
);
$this->_dbTable->insert($data);
Run Code Online (Sandbox Code Playgroud)
_dbTable - >对我的表'Districts'的引用.
现在我想在插入数据之前先清除表格.
我怎样才能做到这一点?
如果屏幕宽度小于 480 像素(移动设备,响应式),我会尝试限制我在 Wordpress 上的帖子。
但是我遇到了问题,因为我发现您不能使用 PHP 来检测屏幕宽度,这是我需要的,因为我使用 PHP 来调整帖子编号。我希望是这样的:
<?php /* Start the Loop */ ?>
<?php if media-screen < 480px {
query_posts('posts_per_page=5'); } ?>
<?php while (have_posts()) : the_post(); ?>
Run Code Online (Sandbox Code Playgroud)
有什么建议?你能以某种方式将一个 css/javascript 布尔值传递到 php 脚本中吗?
编辑:我宁愿不将访问者重定向到移动网站,因为这超出了我的范围。
大家好,这是我的第一个CI项目.
我的模型中有一个简单的表单验证功能.
function verify_login()
{
//This method will have the credentials validation
$this->load->library('form_validation');
$this->form_validation->set_rules('username', 'Username', 'trim|required|xss_clean');
$this->form_validation->set_rules('password', 'Password', 'trim|required|xss_clean|callback_check_database');
var_dump($this->form_validation->run());
die;
if ($this->form_validation->run() == FALSE) {
//Field validation failed. User redirected to login page
$this->load->view('login_view');
} else {
//Go to private area
redirect('home', 'refresh');
}
}
Run Code Online (Sandbox Code Playgroud)
这仅适用于控制器而非模型的情况.当我尝试将变量从控制器传递到模型中的函数时,变量会被接收但不会处理.
有人可以开导我吗?谢谢.
我有以下代码示例
private $analyze_types = array(
"1" => array(
'level' => '4',
'l1' => '-1',
'l2' => '-1',
'l3' => '-1',
'l4' => '-1',
'l5' => '-1'
),
"226" => array(
'level' => '-1',
'l1' => '-1',
'l2' => '-1',
'l3' => '2',
'l4' => '3',
'l5' => '4'
)
);
Run Code Online (Sandbox Code Playgroud)
我如何获得"1"的价值,如果我想获得"水平"价值,我该怎么办?