5 users online. Create an account or sign in to join them.Users

Search

Hi,

I'm still very new to symphony cms. I'm trying to create a custom datasource using SymQLQuery but still trying to get my head wrapped around everything. Using a fresh install of symphony cms, I created a datasource then inserted the example from the SymQLQuery readme.

The code looks like this:

require_once(TOOLKIT . '/class.datasource.php');
require_once(EXTENSIONS . '/symql/lib/class.symql.php');

Class datasourcetest extends Datasource{

           ....


    public function grab(&$param_pool=NULL){
        // create a new SymQLQuery
        $query = new SymQLQuery('published-articles');
        $query
            ->select('title, content, date, publish')
            ->from('articles')
            ->where('published', 'yes')
            ->orderby('system:date', 'desc')
            ->perPage(10)
            ->page(1);

        $result = SymQL::run($query);

        return $result;
    }
}

When I try to view the results in debug mode, I get this error:

SymQL: field 'content' does not exist An error occurred in /Applications/MAMP/htdocs/symphony-2.2.3/extensions/symql/lib/class.symql.php around line 99

Does anyone have any insight on what the issue maybe? Additionally, if someone has some sample code using SymQLQuery to create a datasource that they share that would be greatly appreciated!

Well, as the error says, field content doesn't exist. It is called body.
Another thing is with ->where('published', 'yes'). Field published doesn't exist, it is called publish.

Without testing, just at first glance, this is how it should look like:

// create a new SymQLQuery
$query = new SymQLQuery('published-articles');
$query
    ->select('title, body, date, publish')
    ->from('articles')
    ->where('publish', 'yes')
    ->orderby('system:date', 'desc')
    ->perPage(10)
    ->page(1);

$result = SymQL::run($query);

You're right, I didn't realize the query wasn't using the right field names.

I'm now able to create basic statements that target upper level nodes but don't know how to target fields inside of nodes.

Example:

<entry id="64"> <listing-no handle="007">007</listing-no> <address> <street handle="710-broadway">710 Broadway</street> <city handle="new-york">New York</city> <region handle="ny">NY</region> <postal-code handle="10023">10023</postal-code> <country handle="" /> </address> </entry>

I don't know how to reference the postal-code field. I tried ->where('address::postal-code', '10023') but that just returns everything.

It maps back to whatever field you are using, so if you usual datasource filter was contains: 10023, then the SymQL equivalent would be ->where('address', 'contains: 10023').

SymQL doesn't add any need filtering methods, it merely makes an nice interface, or API if you like, for datasources.

Create an account or sign in to comment.

Symphony • Open Source XSLT CMS

Server Requirements

  • PHP 5.2 or above
  • PHP's LibXML module, with the XSLT extension enabled (--with-xsl)
  • MySQL 5.0 or above
  • An Apache or Litespeed webserver
  • Apache's mod_rewrite module or equivalent

Compatible Hosts

Sign in

Login details