我的表名为post
,列string
名为status
,数据为published
或pending
。现在我想用EntityRepository
类自定义方法从此表中获取所有行,或者只修改现有方法。
我试过这个:
public function queryLatestPublished()
{
return $this->getEntityManager()
->createQuery('
SELECT p
FROM AppBundle:Post
WHERE p.staus == :st
ORDER BY p.created DESC
')
->setParameter('now', new \DateTime())
->setParameter('st', 'published')
;
}
但查询不会返回任何内容。
答案 0 :(得分:0)
您的代码中存在一些错误/问题
我也会改变
select
和from
使用/**
* @param int $limit
* @param int $offset
*
* @return Post[]
*/
public function findNewestPublished($limit = 10, $offset = 0)
{
return $this->createQueryBuilder('p')
->where('p.status = :status')
->setParameter('status', 'published')
->addOrderBy('p.createdAt', 'desc')
->getQuery()
->setFirstResult($offset)
->setMaxResults($limit)
->getResult();
}
和public async Task<Member> AddOrUpdate(DownloadFormModel model)
{
IMailChimpManager mailChimpManager = new MailChimpManager(ConfigurationManager.AppSettings["mailChimpKey"]);
Member member = new Member {EmailAddress = model.Email, Status = Status.Subscribed};
member.MergeFields.Add("NAME", model.Name);
return (await mailChimpManager.Members.AddOrUpdateAsync(ConfigurationManager.AppSettings["mailChimpDownloadListID"], member));
}
我的主张:
public class BuyerDetailFragment extends Fragment {
private TextView TextView;
public static TabLayout tabLayout;
public static ViewPager viewPager;
public static int int_items = 2 ;
private Button request;
public BuyerDetailFragment() {
// Required empty public constructor
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container,
Bundle savedInstanceState) {
View rootView = inflater.inflate(R.layout.fragment_buyer_detail, container, false);
((MainActivity) getActivity())
.setActionBarTitle("مشخصات");
TextView = (TextView)rootView.findViewById(R.id.textView21);
request=(Button)rootView.findViewById(R.id.button3);
request.setBackgroundColor(Color.parseColor("#FF5896E2"));
request.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Create custom dialog object
final Dialog dialog = new Dialog(getActivity());
// Include dialog.xml file
dialog.setContentView(R.layout.request_dialog);
// Set dialog title
dialog.setTitle("درخواست بازدید ملک");
// if decline button is clicked, close the custom dialog
declineButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Close dialog
dialog.dismiss();
}
});
Button acceptButton = (Button) dialog.findViewById(R.id.button6);
// if decline button is clicked, close the custom dialog
acceptButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
// Close dialog
Toast.makeText(getActivity(),"درخواست فرستاده شد",Toast.LENGTH_LONG).show();
dialog.dismiss();
}
});
}
});
String content = getString(R.string.about_house);
Spanned html = Html.fromHtml(content);
TextView.setText(html);
// Inflate the layout for this fragment
tabLayout = (TabLayout) rootView.findViewById(R.id.tabs);
viewPager = (ViewPager) rootView.findViewById(R.id.viewpager);
/**
*Set an Apater for the View Pager
*/
viewPager.setAdapter(new MyAdapter(getChildFragmentManager()));
/**
* Now , this is a workaround ,
* The setupWithViewPager dose't works without the runnable .
* Maybe a Support Library Bug .
*/
tabLayout.post(new Runnable() {
@Override
public void run() {
tabLayout.setupWithViewPager(viewPager);
}
});
return rootView;
}
@Override
public void onAttach(Activity activity) {
super.onAttach(activity);
}
@Override
public void onDetach() {
super.onDetach();
}
class MyAdapter extends FragmentPagerAdapter {
public MyAdapter(FragmentManager fm) {
super(fm);
}
/**
* Return fragment with respect to Position .
*/
@Override
public Fragment getItem(int position)
{
switch (position){
case 0 : return new ImagesFragment();
case 1 : return new ReviewFragment();
}
return null;
}
@Override
public int getCount() {
return int_items;
}
/**
* This method returns the title of the tab according to the position.
*/
@Override
public CharSequence getPageTitle(int position) {
switch (position){
case 0 :
return "تصاویر";
case 1 :
return "نقد و بررسی";
}
return null;
}
}
}
我希望这会有所帮助
答案 1 :(得分:0)
试试这个
$em = $this->getDoctrine()->getManager();
$sql = "SELECT p FROM AppBundle:Post WHERE p.staus = ?1 ORDER BY p.created DESC'";
$query = $em->createQuery($sql);
$query->setParameter(1, 'published');
$result = $query->getResult();