Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to run custom query like db->exec() in a controller? #6

Closed
RNKushwaha opened this issue Jan 18, 2015 · 3 comments
Closed

How to run custom query like db->exec() in a controller? #6

RNKushwaha opened this issue Jan 18, 2015 · 3 comments
Labels

Comments

@RNKushwaha
Copy link

Hi,

I'm trying to develop a dropdown list of published pages when creating a new page. I just want to assign a parent page for each page. How can I show a list of all published pages excluding the current page and assign it to the current page(like an about us, contact us page under about page)?

When I write this code it show error in page_edit.htm
Internal Server Error
Object of class Model\Page could not be converted to string

        $parent = new \Model\Page();
        $parent->filter('page',array('published = ? and publish_date <= ?', true, date('Y-m-d')));
        $parent->countRel('page');
        $this->response->data['parents'] = $parent->find(null,array('order'=>'title asc'));;
        $f3->set('parents',$this->resource->exec("SELECT title FROM fblg_pages where id!='".$params['id']."' and published=1 order by title asc"));

When I tried this code

   $f3->set('parents',$this->resource->exec("SELECT title FROM fblg_pages where id!='".$params['id']."' and published=1 order by title asc"));

It show me error- Fatal error: Call to undefined method Model\Page::exec()

How can I call exec in a controller?

@doonge
Copy link

doonge commented Jan 18, 2015

Model\Page is a Db\Cortex object, which is extended from the Db\Cursor class. Exec() exists in the Db\Sql class, not in the Db\Cursor nor DB\Cortex (which try to remain database system agnostic I think?). If you have an sql database active, try $db->exec('your sql statement')?

I don't think your problem is tied to the fact your code is inside a controller.

@ikkez
Copy link
Owner

ikkez commented Jan 18, 2015

Equivalent to your parents would be:

  $f3->set('parents', $parent->find(array('_id != ? and published = ?',$params['id'],1),array('order'=>'title asc')));

@ikkez ikkez added the question label Jan 18, 2015
@RNKushwaha
Copy link
Author

@ikkez its working now. Thanks

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

3 participants