I have come across retrieving records in PHP. N i came to know we need view, for filtering and other operations. So how can i create view programatically.
You can use the BucketManager to create a design document (containing views) programatically. See: http://docs.couchbase.com/sdk-api/couchbase-php-client-2.0.3/classes/CouchbaseBucketManager.html
Thank you for reply. Can i have a example of setView and getView in php sdk 2.0. and couchbase 3.
Hey,
Here is an example of inserting a new design document using the SDK 2.0 API’s:
$bucketmgr = $bucket->manager();
$bucketmgr->insertDesignDocument('DDOC_NAME', array(
'views' => array(
'1ST_VIEW_NAME' => array( 'map' => 'VIEW_JAVASCRIPT' ),
'2ND_VIEW_NAME' => array( 'map' => 'VIEW_JAVASCRIPT' )
)
));
Cheers, Brett
I tried the example.It is showing already exist error… So i even tried upsertDesignDocument, retuns true…
But designDocument is not created. I m using php sdk 2.0.3
@keshav_katwe did you make sure to look in the published section? I think it will create a non-development design doc by default.
What is the exact error?
This is the error which i m getting.
Fatal error: Uncaught exception ‘CouchbaseException’ with message ‘design document already exists’ in [CouchbaseNative]/CouchbaseBucketManager.class.php:70 Stack trace: #0 C:\xampp\htdocs\couch\example.php(15): CouchbaseBucketManager->insertDesignDocument(‘say1’, Array) #1 {main} thrown in [CouchbaseNative]/CouchbaseBucketManager.class.php on line 70
Here is my code.
<?php
$clusterConnection = new CouchbaseCluster('couchbase://localhost');
$bucket = $clusterConnection->openBucket('default');
$backetManager = $bucket->manager();
$data = array(
'views' => array(
'SAY2' => array( 'map' => 'function (doc, meta) { emit(doc.name, doc); }' )
)
);
$result = $backetManager->insertDesignDocument('say1', $data);